--- libaitio/src/aitio.c 2011/06/07 11:49:39 1.6 +++ libaitio/src/aitio.c 2011/10/31 13:53:51 1.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.c,v 1.6 2011/06/07 11:49:39 misho Exp $ +* $Id: aitio.c,v 1.7 2011/10/31 13:53:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -557,4 +557,30 @@ ioWatchDirLoop(const char *csDir, int (*callback)(cons close(d); close(kq); return n; +} + +/* + * ioCreatePIDFile() Create PID file + * @csName = PID filename + * @ifExists = !=0 if filename exists return error + * return: -1 error or 0 ok + */ +inline int +ioCreatePIDFile(const char *csName, int ifExists) +{ + int fd; + char str[STRSIZ] = { 0 }; + + if (!csName) + return -1; + + fd = open(csName, O_WRONLY | O_CREAT | (ifExists ? O_EXCL : 0), 0644); + if (fd == -1) { + LOGERR; + return -1; + } + snprintf(str, sizeof str, "%d", getpid()); + write(fd, str, strlen(str)); + close(fd); + return 0; }