diff options
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/debug.c | 2 | ||||
-rw-r--r-- | source/lib/fault.c | 2 | ||||
-rw-r--r-- | source/lib/genrand.c | 2 | ||||
-rw-r--r-- | source/lib/ms_fnmatch.c | 2 | ||||
-rw-r--r-- | source/lib/pidfile.c | 2 | ||||
-rw-r--r-- | source/lib/smbrun.c | 2 | ||||
-rw-r--r-- | source/lib/substitute.c | 2 | ||||
-rw-r--r-- | source/lib/system.c | 32 | ||||
-rw-r--r-- | source/lib/util.c | 6 |
9 files changed, 42 insertions, 10 deletions
diff --git a/source/lib/debug.c b/source/lib/debug.c index ed27b93cfd0..675c2d8cfcb 100644 --- a/source/lib/debug.c +++ b/source/lib/debug.c @@ -580,7 +580,7 @@ BOOL dbghdr( int level, char *file, char *func, int line ) header_str[0] = '\0'; if( lp_debug_pid()) - slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid()); + slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid()); if( lp_debug_uid()) { size_t hs_len = strlen(header_str); diff --git a/source/lib/fault.c b/source/lib/fault.c index 6effaf7d7c6..29272f19280 100644 --- a/source/lib/fault.c +++ b/source/lib/fault.c @@ -38,7 +38,7 @@ static void fault_report(int sig) counter++; DEBUG(0,("===============================================================\n")); - DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)getpid(),VERSION)); + DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),VERSION)); DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n")); DEBUG(0,("===============================================================\n")); diff --git a/source/lib/genrand.c b/source/lib/genrand.c index a9698d4cd1b..102eec63009 100644 --- a/source/lib/genrand.c +++ b/source/lib/genrand.c @@ -163,7 +163,7 @@ static uint32 do_reseed(unsigned char *md4_outbuf) * Finally add the counter, time of day, and pid. */ GetTimeOfDay(&tval); - mypid = getpid(); + mypid = sys_getpid(); v1 = (counter++) + mypid + tval.tv_sec; v2 = (counter++) * mypid + tval.tv_usec; diff --git a/source/lib/ms_fnmatch.c b/source/lib/ms_fnmatch.c index ee9b1cf985e..364fd6f347a 100644 --- a/source/lib/ms_fnmatch.c +++ b/source/lib/ms_fnmatch.c @@ -36,6 +36,8 @@ matching routine! NOTE: this matches only filenames with no directory component + + Returns 0 on match, -1 on fail. */ int ms_fnmatch(char *pattern, char *string) { diff --git a/source/lib/pidfile.c b/source/lib/pidfile.c index 726e8c1f21a..a6dc327fd7a 100644 --- a/source/lib/pidfile.c +++ b/source/lib/pidfile.c @@ -101,7 +101,7 @@ void pidfile_create(char *name) } memset(buf, 0, sizeof(buf)); - slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) getpid()); + slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) sys_getpid()); if (write(fd, buf, sizeof(buf)) != sizeof(buf)) { DEBUG(0,("ERROR: can't write to file %s: %s\n", pidFile, strerror(errno))); diff --git a/source/lib/smbrun.c b/source/lib/smbrun.c index 8d666980b38..81dfc10dfb1 100644 --- a/source/lib/smbrun.c +++ b/source/lib/smbrun.c @@ -124,7 +124,7 @@ int smbrun(char *cmd,char *outfile,BOOL shared) CatchChildLeaveStatus(); - if ((pid=fork()) < 0) { + if ((pid=sys_fork()) < 0) { DEBUG(0,("smbrun: fork failed with error %s\n", strerror(errno) )); CatchChild(); return errno; diff --git a/source/lib/substitute.c b/source/lib/substitute.c index c43c133d6ad..2a575f0c382 100644 --- a/source/lib/substitute.c +++ b/source/lib/substitute.c @@ -176,7 +176,7 @@ void standard_sub_basic(char *str) case 'T' : string_sub(p,"%T", timestring(False),l); break; case 'a' : string_sub(p,"%a", remote_arch,l); break; case 'd' : - slprintf(pidstr,sizeof(pidstr), "%d",(int)getpid()); + slprintf(pidstr,sizeof(pidstr), "%d",(int)sys_getpid()); string_sub(p,"%d", pidstr,l); break; case 'h' : string_sub(p,"%h", myhostname(),l); break; diff --git a/source/lib/system.c b/source/lib/system.c index 539f21d49c1..80a968b634c 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -933,10 +933,40 @@ static char **extract_args(const char *command) } /************************************************************************** + Wrapper for fork. Ensures that mypid is reset. Used so we can write + a sys_getpid() that only does a system call *once*. +****************************************************************************/ + +static pid_t mypid = (pid_t)-1; + +pid_t sys_fork(void) +{ + pid_t forkret = fork(); + + if (forkret == (pid_t)0) /* Child - reset mypid so sys_getpid does a system call. */ + mypid = (pid_t) -1; + + return forkret; +} + +/************************************************************************** + Wrapper for getpid. Ensures we only do a system call *once*. +****************************************************************************/ + +pid_t sys_getpid(void) +{ + if (mypid == (pid_t)-1) + mypid = getpid(); + + return mypid; +} + +/************************************************************************** Wrapper for popen. Safer as it doesn't search a path. Modified from the glibc sources. modified by tridge to return a file descriptor. We must kick our FILE* habit ****************************************************************************/ + typedef struct _popen_list { int fd; @@ -974,7 +1004,7 @@ int sys_popen(const char *command) if(!(argl = extract_args(command))) goto err_exit; - entry->child_pid = fork(); + entry->child_pid = sys_fork(); if (entry->child_pid == -1) { goto err_exit; diff --git a/source/lib/util.c b/source/lib/util.c index 955e1df080a..8ac9223f2eb 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -741,7 +741,7 @@ become a daemon, discarding the controlling terminal ****************************************************************************/ void become_daemon(void) { - if (fork()) { + if (sys_fork()) { _exit(0); } @@ -1584,7 +1584,7 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) if ((ret != -1) && (lock.l_type != F_UNLCK) && (lock.l_pid != 0) && - (lock.l_pid != getpid())) + (lock.l_pid != sys_getpid())) { DEBUG(3,("fd %d is locked by pid %d\n",fd,(int)lock.l_pid)); return(True); @@ -2110,7 +2110,7 @@ int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6) char pidstr[10]; pstring cmd = "/usr/X11R6/bin/xterm -display :0 -T Panic -n Panic -e /bin/sh -c 'cat /tmp/ierrs.*.%d ; gdb /proc/%d/exe %d'"; - slprintf(pidstr, sizeof(pidstr), "%d", getpid()); + slprintf(pidstr, sizeof(pidstr), "%d", sys_getpid()); pstring_sub(cmd, "%d", pidstr); if (!fn) { |