]>
git.proxmox.com Git - mirror_frr.git/blob - lib/pid_output.c
3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #define PIDFILE_MASK 0644
31 pid_output (const char *path
)
42 oldumask
= umask(0777 & ~PIDFILE_MASK
);
43 fd
= open (path
, O_RDWR
| O_CREAT
, PIDFILE_MASK
);
46 zlog_err("Can't create pid lock file %s (%s), exiting",
47 path
, safe_strerror(errno
));
56 memset (&lock
, 0, sizeof(lock
));
60 lock
.l_type
= F_WRLCK
;
61 lock
.l_whence
= SEEK_SET
;
63 if (fcntl(fd
, F_SETLK
, &lock
) < 0)
65 zlog_err("Could not lock pid_file %s, exiting", path
);
69 sprintf (buf
, "%d\n", (int) pid
);
70 pidsize
= strlen(buf
);
71 if ((tmp
= write (fd
, buf
, pidsize
)) != (int)pidsize
)
72 zlog_err("Could not write pid %d to pid_file %s, rc was %d: %s",
73 (int)pid
,path
,tmp
,safe_strerror(errno
));
74 else if (ftruncate(fd
, pidsize
) < 0)
75 zlog_err("Could not truncate pid_file %s to %u bytes: %s",
76 path
,(u_int
)pidsize
,safe_strerror(errno
));