Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!sdd.hp.com!wuarchive!udel!princeton!phoenix!pfalstad From: pfalstad@phoenix.princeton.edu (Paul Falstad) Newsgroups: comp.unix.questions Subject: Re: How do I unset TXTBSY on a daemon's binary? Message-ID: <34050@sahkmet.Princeton.EDU> Date: 10 May 91 09:17:29 GMT References: <1991May10.042300.5901@massey.ac.nz> Sender: gnus@idunno.Princeton.EDU Organization: League For Fighting Chartered Accountancy Lines: 61 A.Raman@massey.ac.nz (A.V.Raman) wrote: >1. What is the accepted procedure to unset the TXTBSY flag on the binary > after the daemon backgrounds itself? >2. How do I find out if a particular user is logged on from within a C > program. > >I need to do (1) because I want to be able to make changes to the code >and compile and reinstall it, but the changes are not so important that >the currently running daemon needs to be killed and restarted. Currently >when I try to install a new version when the old daemon is running, I >get the error message: Text file busy. Instead of trying to copy the new file on top of the old one, remove the old file first, and then put the new file there. You don't want to unset the TXTBSY flag; if you do this, the running daemon will probably dump core the next time it page faults in the text segment. >I need to do (2) because I want to find out whether I must write a >user or mail him regarding some status change he required. I tried doing >a man -k on "user", "wtmp", "logg" etc., but none gives me any info about >a C library function / System call that tells me whether a particular user >is logged on. Easy way: int ison(char *s) { char buf[BUFSIZ]; sprintf(buf,"who|grep %s >/dev/null",s); /* or grep -s */ return !system(buf); } Hard way: #include #include int ison(char *s) { struct utmp u; FILE *in; int ret = 0; in = fopen("/etc/utmp","r"); while (fread(&u,sizeof u,1,in)) #ifdef USER_PROCESS if (u.ut_type == USER_PROCESS) #else if (u.ut_name[0]) #endif if (ret = !strncmp(u.ut_name,s,8)) break; fclose(in); return ret; } This code is probably wrong; it's taken from zsh. :-) -- Paul Falstad pfalstad@phoenix.princeton.edu And on the roads, too, vicious gangs of KEEP LEFT signs! If Princeton knew my opinions, they'd have expelled me long ago.