From: utzoo!decvax!decwrl!sun!megatest!fortune!hpda!hplabs!sri-unix!chris.umcp-cs@UDel-Relay Newsgroups: net.unix-wizards Title: Re: root executing setuid programs Article-I.D.: sri-arpa.763 Posted: Thu Mar 10 00:28:03 1983 Received: Fri Apr 1 07:20:56 1983 From: Chris Torek From: hplabs!hao!csu-cs!bentson@UCB-C70 The line printer daemon and other utilities have a need for mutual exclusion because they can be simultaneously invoked by many users. Since there is no such intrinsic in U*nx, there is an idiomatic expression that provides the same effect.... The U*nx idiom is to create a file with "0" permission so that a second attempt to create a file will fail.... HOWEVER, if either the program is owned by superuser and is setuid or the program is run by superuser the example will not work as predicted.... There is a better idiomatic expression: unlink (tempfile); creat (tempfile, mode); if (link (tempfile, lockfile) < 0) { /* someone else is doing the work */ exit (0); } The link system call will not let ANYONE link one file to another if the second file exists.