pidfile.c File Reference

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "debug.h"

Include dependency graph for pidfile.c:

Go to the source code of this file.

Functions

int pidfile_acquire (char *pidfile)
void pidfile_write_release (int pid_fd)
void pidfile_delete (char *pidfile)


Function Documentation

int pidfile_acquire ( char *  pidfile  ) 

Definition at line 32 of file pidfile.c.

References LOG, and LOG_ERR.

Referenced by udhcp().

00033 {
00034         int pid_fd;
00035         if (pidfile == NULL) return -1;
00036 
00037         pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644);
00038         if (pid_fd < 0) {
00039                 LOG(LOG_ERR, "Unable to open pidfile %s: %s\n",
00040                     pidfile, strerror(errno));
00041         } else {
00042                 lockf(pid_fd, F_LOCK, 0);
00043         }
00044         
00045         return pid_fd;
00046 }

void pidfile_delete ( char *  pidfile  ) 

Definition at line 64 of file pidfile.c.

00065 {
00066         if (pidfile) unlink(pidfile);
00067 }

void pidfile_write_release ( int  pid_fd  ) 

Definition at line 49 of file pidfile.c.

Referenced by udhcp().

00050 {
00051         FILE *out;
00052 
00053         if (pid_fd < 0) return;
00054 
00055         if ((out = fdopen(pid_fd, "w")) != NULL) {
00056                 fprintf(out, "%d\n", getpid());
00057                 fclose(out);
00058         }
00059         lockf(pid_fd, F_UNLCK, 0);
00060         close(pid_fd);
00061 }


Generated on Tue Jan 15 12:24:47 2008 for Dynamics 0.8.1.Dynamo.1 by  doxygen 1.5.1