of doing a system call every time we want to just get our pid.
Jeremy.
}
DEBUG(0, ("DCE login succeeded for principal %s on pid %d\n",
- user, getpid()));
+ user, sys_getpid()));
DEBUG(3, ("DCE principal: %s\n"
" uid: %d\n"
dce_error_inq_text(err, dce_errstr, &err2);
DEBUG(0,
("DCE purge login context failed for server instance %d: %s\n",
- getpid(), dce_errstr));
+ sys_getpid(), dce_errstr));
}
}
#endif
}
(void)slprintf(tkfile, sizeof(tkfile) - 1, "/tmp/samba_tkt_%d",
- (int)getpid());
+ (int)sys_getpid());
krb_set_tkt_string(tkfile);
if (krb_verify_user(user, "", realm, password, 0, "rmcd") == KSUCCESS)
fstrcat(rname,"\\");
slprintf(tmpname,
sizeof(fstring)-1,
- "%s/smbmore.%d",tmpdir(),(int)getpid());
+ "%s/smbmore.%d",tmpdir(),(int)sys_getpid());
fstrcpy(lname,tmpname);
if (!next_token(NULL,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
FILE *f;
slprintf(tmpname,sizeof(pstring)-1,
- "%s/ls.smb.%d",tmpdir(),(int)getpid());
+ "%s/ls.smb.%d",tmpdir(),(int)sys_getpid());
if (recurse)
slprintf(cmd,sizeof(pstring)-1,
"find . -name \"%s\" -print > %s",p,tmpname);
pstrcpy(rname,lname);
p = strrchr(rname,'/');
if (p) {
- slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)getpid());
+ slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)sys_getpid());
}
if (strequal(lname,"-")) {
- slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)getpid());
+ slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)sys_getpid());
}
do_put(rname, lname);
signal( SIGTERM, exit_parent );
- if ((child_pid = fork()) < 0) {
+ if ((child_pid = sys_fork()) < 0) {
fprintf(stderr,"could not fork\n");
}
args[i++] = xstrdup(tmp);
}
- if (fork() == 0) {
+ if (sys_fork() == 0) {
if (file_exist(BINDIR "/smbmnt", NULL)) {
execv(BINDIR "/smbmnt", args);
fprintf(stderr,"execv of %s failed. Error was %s.", BINDIR "/smbmnt", strerror(errno));
smb_ucs2_t *wsys_getwd(smb_ucs2_t *s);
int wsys_chown(const smb_ucs2_t *wfname, uid_t uid, gid_t gid);
int wsys_chroot(const smb_ucs2_t *wfname);
+pid_t sys_fork(void);
+pid_t sys_getpid(void);
int sys_popen(const char *command);
int sys_pclose(int fd);
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);
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"));
* 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;
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)
{
}
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)));
CatchChildLeaveStatus();
- if ((pid=fork()) < 0) {
+ if ((pid=sys_fork()) < 0) {
DEBUG(0,("smbrun: fork failed with error %s\n", strerror(errno) ));
CatchChild();
return errno;
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;
return argl;
}
+/**************************************************************************
+ 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;
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;
****************************************************************************/
void become_daemon(void)
{
- if (fork()) {
+ if (sys_fork()) {
_exit(0);
}
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);
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) {
cli->port = 0;
cli->fd = -1;
cli->cnum = -1;
- cli->pid = (uint16)getpid();
+ cli->pid = (uint16)sys_getpid();
cli->mid = 1;
cli->vuid = UID_FIELD_INVALID;
cli->protocol = PROTOCOL_NT1;
static int trn_id;
if (trn_id == 0) {
- srandom(getpid());
+ srandom(sys_getpid());
}
trn_id = random();
return(False);
ret = !brl_locktest(fsp->dev, fsp->inode,
- global_smbpid, getpid(), conn->cnum,
+ global_smbpid, sys_getpid(), conn->cnum,
offset, count, lock_type);
/*
if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
ok = brl_lock(fsp->dev, fsp->inode, fsp->fnum,
- global_smbpid, getpid(), conn->cnum,
+ global_smbpid, sys_getpid(), conn->cnum,
offset, count,
lock_type);
* lock entry.
*/
(void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
- global_smbpid, getpid(), conn->cnum,
+ global_smbpid, sys_getpid(), conn->cnum,
offset, count);
}
}
*/
ok = brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
- global_smbpid, getpid(), conn->cnum, offset, count);
+ global_smbpid, sys_getpid(), conn->cnum, offset, count);
if (!ok) {
DEBUG(10,("do_unlock: returning ERRlock.\n" ));
void locking_close_file(files_struct *fsp)
{
- pid_t pid = getpid();
+ pid_t pid = sys_getpid();
if (!lp_locking(SNUM(fsp->conn)))
return;
struct locking_data *data;
int i, del_count=0;
share_mode_entry *shares;
- pid_t pid = getpid();
+ pid_t pid = sys_getpid();
/* read in the existing share modes */
dbuf = tdb_fetch(tdb, locking_key_fsp(fsp));
static void fill_share_mode(char *p, files_struct *fsp, uint16 port, uint16 op_type)
{
share_mode_entry *e = (share_mode_entry *)p;
- e->pid = getpid();
+ e->pid = sys_getpid();
e->share_mode = fsp->share_mode;
e->op_port = port;
e->op_type = op_type;
struct locking_data *data;
int i;
share_mode_entry *shares;
- pid_t pid = getpid();
+ pid_t pid = sys_getpid();
int need_store=0;
/* read in the existing share modes */
return;
}
- child_pid = fork();
+ child_pid = sys_fork();
if (child_pid) {
fd_in = fd1[0];
StartupTime = time(NULL);
- sys_srandom(time(NULL) ^ getpid());
+ sys_srandom(time(NULL) ^ sys_getpid());
TimeInit();
if (!name_trn_id)
{
- name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)getpid()%(unsigned)100);
+ name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100);
}
name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF;
return name_trn_id;
/* the parent forks and returns, leaving the child to do the
actual sync */
CatchChild();
- if ((s->pid = fork())) return;
+ if ((s->pid = sys_fork())) return;
BlockSignals( False, SIGTERM );
doesn't block while this is done */
if (background) {
CatchChild();
- if (fork()) {
+ if (sys_fork()) {
return;
}
}
slprintf(fname,sizeof(fname),"%s/%s", lp_lockdir(), WINS_LIST);
all_string_sub(fname,"//", "/", 0);
- slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)getpid());
+ slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)sys_getpid());
if((fp = sys_fopen(fnamenew,"w")) == NULL)
{
}
DEBUG(0, ("DCE login succeeded for principal %s on pid %d\n",
- user, getpid()));
+ user, sys_getpid()));
DEBUG(3, ("DCE principal: %s\n"
" uid: %d\n"
dce_error_inq_text(err, dce_errstr, &err2);
DEBUG(0,
("DCE purge login context failed for server instance %d: %s\n",
- getpid(), dce_errstr));
+ sys_getpid(), dce_errstr));
}
}
#endif
}
(void)slprintf(tkfile, sizeof(tkfile) - 1, "/tmp/samba_tkt_%d",
- (int)getpid());
+ (int)sys_getpid());
krb_set_tkt_string(tkfile);
if (krb_verify_user(user, "", realm, password, 0, "rmcd") == KSUCCESS)
FILE *fp_write = NULL;
int pfile2_lockdepth = 0;
- slprintf(pfile2, sizeof(pfile2)-1, "%s.%u", pfile, (unsigned)getpid() );
+ slprintf(pfile2, sizeof(pfile2)-1, "%s.%u", pfile, (unsigned)sys_getpid() );
/*
* Open the smbpassword file - for update. It needs to be update
****************************************************************************/
BOOL print_backend_init(void)
{
- if (tdb && local_pid == getpid()) return True;
+ if (tdb && local_pid == sys_getpid()) return True;
tdb = tdb_open(lock_path("printing.tdb"), 0, 0, O_RDWR|O_CREAT, 0600);
if (!tdb) {
DEBUG(0,("Failed to open printing backend database\n"));
}
- local_pid = getpid();
+ local_pid = sys_getpid();
/* handle a Samba upgrade */
tdb_writelock(tdb);
SIVAL(hnd->data, 4 , pol_hnd_low ); /* second bit is incrementing */
SIVAL(hnd->data, 8 , pol_hnd_high); /* second bit is incrementing */
SIVAL(hnd->data, 12, time(NULL)); /* something random */
- SIVAL(hnd->data, 16, getpid()); /* something more random */
+ SIVAL(hnd->data, 16, sys_getpid()); /* something more random */
}
/****************************************************************************
*/
become_root(False); /* to connect to pipe */
- p->m = msrpc_use_add(p->name, getpid(), &usr, False);
+ p->m = msrpc_use_add(p->name, sys_getpid(), &usr, False);
unbecome_root(False);
if (p->m == NULL)
log files and prevents client bugs where pipe numbers are reused
over connection restarts */
if (next_pipe == 0)
- next_pipe = (getpid() ^ time(NULL)) % MAX_OPEN_PIPES;
+ next_pipe = (sys_getpid() ^ time(NULL)) % MAX_OPEN_PIPES;
i = bitmap_find(bmap, next_pipe);
SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
SIVAL(hnd->data, 12, time(NULL)); /* something random */
- SIVAL(hnd->data, 16, getpid()); /* something more random */
+ SIVAL(hnd->data, 16, sys_getpid()); /* something more random */
}
/****************************************************************************
CatchChildLeaveStatus();
- if ((pid = fork()) < 0)
+ if ((pid = sys_fork()) < 0)
{
DEBUG(3,
("Cannot fork() child for password change: %s\n",
DEBUG(3,("Yielding connection to %s\n",name));
ZERO_STRUCT(key);
- key.pid = getpid();
+ key.pid = sys_getpid();
if (conn) key.cnum = conn->cnum;
fstrcpy(key.name, name);
DEBUG(5,("claiming %s %d\n",name,max_connections));
ZERO_STRUCT(key);
- key.pid = getpid();
+ key.pid = sys_getpid();
key.cnum = conn?conn->cnum:-1;
fstrcpy(key.name, name);
/* fill in the crec */
ZERO_STRUCT(crec);
crec.magic = 0x280267;
- crec.pid = getpid();
+ crec.pid = sys_getpid();
crec.cnum = conn?conn->cnum:-1;
if (conn) {
crec.uid = conn->uid;
if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
share_mode_entry *share_list = NULL;
- pid_t pid = getpid();
+ pid_t pid = sys_getpid();
int token = -1;
int num_share_modes = 0;
int i;
increases the chance that the errant client will get an error rather
than causing corruption */
if (first_file == 0) {
- first_file = (getpid() ^ (int)time(NULL)) % real_max_open_files;
+ first_file = (sys_getpid() ^ (int)time(NULL)) % real_max_open_files;
}
i = bitmap_find(file_bmap, first_file);
SSVAL(outbuf,smb_vwv4,1);
SSVAL(outbuf,smb_vwv5,raw); /* tell redirector we support
readbraw writebraw (possibly) */
- SIVAL(outbuf,smb_vwv6,getpid());
+ SIVAL(outbuf,smb_vwv6,sys_getpid());
SSVAL(outbuf,smb_vwv10, TimeDiff(t)/60);
put_dos_date(outbuf,smb_vwv8,t);
set_message(outbuf,13,crypt_len,True);
SSVAL(outbuf,smb_vwv1,secword);
- SIVAL(outbuf,smb_vwv6,getpid());
+ SIVAL(outbuf,smb_vwv6,sys_getpid());
if (doencrypt)
memcpy(smb_buf(outbuf), cryptkey, 8);
SSVAL(outbuf,smb_vwv2+1,1); /* num vcs */
SIVAL(outbuf,smb_vwv3+1,0xffff); /* max buffer. LOTS! */
SIVAL(outbuf,smb_vwv5+1,0x10000); /* raw size. full 64k */
- SIVAL(outbuf,smb_vwv7+1,getpid()); /* session key */
+ SIVAL(outbuf,smb_vwv7+1,sys_getpid()); /* session key */
SIVAL(outbuf,smb_vwv9+1,capabilities); /* capabilities */
put_long_date(outbuf+smb_vwv11+1,t);
SSVALS(outbuf,smb_vwv15+1,TimeDiff(t)/60);
{
int access_allowed = access_table(deny_mode,old_deny_mode,old_open_mode,
- (share->pid == getpid()),is_executable(fname));
+ (share->pid == sys_getpid()),is_executable(fname));
if ((access_allowed == AFAIL) ||
(!fcbopen && (access_allowed == AREAD && *flags == O_RDWR)) ||
share_mode_entry *old_shares = 0;
int num_share_modes;
SMB_STRUCT_STAT sbuf;
- pid_t pid = getpid();
+ pid_t pid = sys_getpid();
SMB_DEV_T dev;
SMB_INO_T inode;
return False;
DEBUG(3,("open_oplock ipc: pid = %d, global_oplock_port = %u\n",
- (int)getpid(), global_oplock_port));
+ (int)sys_getpid(), global_oplock_port));
return True;
}
{
char op_break_msg[OPLOCK_BREAK_MSG_LEN];
struct sockaddr_in addr_out;
- pid_t pid = getpid();
+ pid_t pid = sys_getpid();
time_t start_time;
int time_left;
long usec;
set_process_capability(KERNEL_OPLOCK_CAPABILITY,True);
set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY,True);
- slprintf(tmpname,sizeof(tmpname)-1, "%s/koplock.%d", lp_lockdir(), (int)getpid());
+ slprintf(tmpname,sizeof(tmpname)-1, "%s/koplock.%d", lp_lockdir(), (int)sys_getpid());
if(pipe(pfd) != 0) {
DEBUG(0,("check_kernel_oplocks: Unable to create pipe. Error was %s\n",
/* get a sort-of random number */
GetTimeOfDay(&tval);
- v1 = (counter++) + getpid() + tval.tv_sec;
- v2 = (counter++) * getpid() + tval.tv_usec;
+ v1 = (counter++) + sys_getpid() + tval.tv_sec;
+ v2 = (counter++) * sys_getpid() + tval.tv_usec;
SIVAL(challenge,0,v1);
SIVAL(challenge,4,v2);
extern int global_smbpid;
if (pid == (pid_t)-1)
- pid = getpid();
+ pid = sys_getpid();
errno = 0;
last_message = type;
continue;
}
- if (smbd_server_fd() != -1 && fork()==0) {
+ if (smbd_server_fd() != -1 && sys_fork()==0) {
/* Child code ... */
/* close the listening socket(s) */
dbgtext( "connect to service %s ", lp_servicename(SNUM(conn)) );
dbgtext( "as user %s ", user );
dbgtext( "(uid=%d, gid=%d) ", (int)geteuid(), (int)getegid() );
- dbgtext( "(pid %d)\n", (int)getpid() );
+ dbgtext( "(pid %d)\n", (int)sys_getpid() );
}
/* we've finished with the sensitive stuff */