[tuxdroid-svn] r253 - svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment va
Status: Beta
Brought to you by:
ks156
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-14 09:15:56
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 253 Modified: daemon/trunk/libs/USBDaemon_pidfile.c daemon/trunk/libs/USBDaemon_pidfile.h Log: neimad 2007-04-14 10:56:06 +0200 (Sat, 14 Apr 2007) 319 * Made PID handling code comply with the official coding style (ie, 4 spaces indentation, opening curly brace on a line by itself, no space between function name and arguments, etc). * Constant PidFile renamed to PIDFILE to follow common practice. * Didn't touch comments; these should follow doxygen formatting. svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_pidfile.c =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.c 2007-04-14 07:53:22 UTC (rev 252) +++ daemon/trunk/libs/USBDaemon_pidfile.c 2007-04-14 08:56:06 UTC (rev 253) @@ -30,10 +30,10 @@ #include <signal.h> #include "USBDaemon_globals.h" -#define PidFile "/var/run/tuxdaemon.pid" +#define PIDFILE "/var/run/tuxdaemon.pid" /************************************************************************ */ -/* Functions to deal with the pidfile +/* Functions to deal with the pidfile Their original version come from the sysklogd package, under GPL Copyright (c) 1995 Martin Schulze <Mar...@Li...> */ /************************************************************************ */ @@ -44,16 +44,18 @@ * 0 is returned if either there's no pidfile, it's empty * or no pid can be read. */ -int read_pid (void) +int read_pid(void) { - FILE *f; - int pid; + FILE *f; + int pid; - if (!(f=fopen(PidFile,"r"))) - return 0; - fscanf(f,"%d", &pid); - fclose(f); - return pid; + if (!(f = fopen(PIDFILE, "r"))) + return 0; + + fscanf(f, "%d", &pid); + fclose(f); + + return pid; } /* check_pid @@ -62,24 +64,24 @@ * table (using /proc) to determine if the process already exists. If * so 1 is returned, otherwise 0. */ -int check_pid (void) +int check_pid(void) { - int pid = read_pid(); + int pid = read_pid(); - /* Amazing ! _I_ am already holding the pid file... */ - if ((!pid) || (pid == getpid ())) - return 0; + /* Amazing ! _I_ am already holding the pid file... */ + if (!pid || pid == getpid()) + return 0; - /* - * The 'standard' method of doing this is to try and do a 'fake' kill - * of the process. If an ESRCH error is returned the process cannot - * be found -- GW - */ - /* But... errno is usually changed only on error.. */ - if (kill(pid, 0) && errno == ESRCH) - return(0); + /* + * The 'standard' method of doing this is to try and do a 'fake' kill + * of the process. If an ESRCH error is returned the process cannot + * be found -- GW + */ + /* But... errno is usually changed only on error.. */ + if (kill(pid, 0) && errno == ESRCH) + return 0; - return pid; + return pid; } /* write_pid @@ -87,41 +89,47 @@ * Writes the pid to the specified file. If that fails 0 is * returned, otherwise the pid. */ -int write_pid (void) +int write_pid(void) { - FILE *f; - int fd; - int pid; + FILE *f; + int fd; + int pid; - if ( ((fd = open(PidFile, O_RDWR|O_CREAT|O_TRUNC, 0644)) == -1) - || ((f = fdopen(fd, "r+")) == NULL) ) { - fprintf(stderr, "Can't open or create %s.\n", PidFile); - return 0; - } + if ((fd = open(PIDFILE, O_RDWR|O_CREAT|O_TRUNC, 0644)) == -1 + || (f = fdopen(fd, "r+")) == NULL) + { + fprintf(stderr, "Can't open or create %s: %m\n", PIDFILE); + return 0; + } - if (flock(fd, LOCK_EX|LOCK_NB) == -1) { - fscanf(f, "%d", &pid); - fclose(f); - fprintf(stderr, "Can't lock, lock is held by pid %d.\n", pid); - return 0; - } + if (flock(fd, LOCK_EX|LOCK_NB) == -1) + { + fscanf(f, "%d", &pid); + fclose(f); + fprintf(stderr, "Can't lock, lock is held by pid %d.\n", pid); + return 0; + } - pid = getpid(); - if (!fprintf(f,"%d\n", pid)) { - fprintf(stderr, "Can't write pid , %s.\n", strerror(errno)); - close(fd); - return 0; - } - fflush(f); + pid = getpid(); + if (!fprintf(f,"%d\n", pid)) + { + fprintf(stderr, "Can't write pid: %m.\n"); + close(fd); + return 0; + } + fflush(f); - if (flock(fd, LOCK_UN) == -1) { - fprintf(stderr, "Can't unlock pidfile %s, %s.\n", PidFile, strerror(errno)); - close(fd); - return 0; - } - close(fd); - chown(PidFile, NEWUID, NEWGID); - return pid; + if (flock(fd, LOCK_UN) == -1) + { + fprintf(stderr, "Can't unlock pidfile %s: %m.\n", PIDFILE); + close(fd); + return 0; + } + + close(fd); + chown(PIDFILE, NEWUID, NEWGID); + + return pid; } /* remove_pid @@ -129,18 +137,18 @@ * Remove the the specified file. The result from unlink(2) * is returned */ -int remove_pid (void) +int remove_pid(void) { - return unlink (PidFile); + return unlink(PIDFILE); } - + /************************************************************************ */ /* Terminate */ /************************************************************************ */ void terminate(int ret) { - if (remove_pid()) { - fprintf(stderr, "Could not delete PID file\n"); - } + if (remove_pid()) + fprintf(stderr, "Could not delete PID file\n"); + exit(ret); } Modified: daemon/trunk/libs/USBDaemon_pidfile.h =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.h 2007-04-14 07:53:22 UTC (rev 252) +++ daemon/trunk/libs/USBDaemon_pidfile.h 2007-04-14 08:56:06 UTC (rev 253) @@ -20,7 +20,7 @@ /* $Id: main.c 242 2007-04-13 08:48:33Z remi $ */ /************************************************************************ */ -/* Functions to deal with the pidfile +/* Functions to deal with the pidfile Their original version come from the sysklogd package, under GPL Copyright (c) 1995 Martin Schulze <Mar...@Li...> */ /************************************************************************ */ @@ -31,7 +31,7 @@ * 0 is returned if either there's no pidfile, it's empty * or no pid can be read. */ -extern int read_pid (void); +extern int read_pid(void); /* check_pid * @@ -39,21 +39,21 @@ * table (using /proc) to determine if the process already exists. If * so 1 is returned, otherwise 0. */ -extern int check_pid (void); +extern int check_pid(void); /* write_pid * * Writes the pid to the specified file. If that fails 0 is * returned, otherwise the pid. */ -extern int write_pid (void); +extern int write_pid(void); /* remove_pid * * Remove the the specified file. The result from unlink(2) * is returned */ -extern int remove_pid (void); +extern int remove_pid(void); /* terminate * |