Discussion:
/usr/src/usr.sbin/lpr/common_source/rmjob.c diff
Chris Bennett
2016-01-26 17:40:44 UTC
Permalink
I found this in several other files in lpr src directories.
Doesn't seem to get used in any lp* files or connect with anything
higher up.

Am I looking at this correctly or way off?
Thanks,
Chris


Index: rmjob.c
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/common_source/rmjob.c,v
retrieving revision 1.23
diff -u -p -r1.23 rmjob.c
--- rmjob.c 12 Jan 2016 23:35:13 -0000 1.23
+++ rmjob.c 26 Jan 2016 17:36:10 -0000
@@ -62,7 +62,6 @@ static int all = 0; /* eliminate all fi
static int cur_daemon; /* daemon's pid */
static char current[NAME_MAX]; /* active control file name */

-static void alarmer(int);
static int chk(char *);
static void do_unlink(char *);
static int iscf(const struct dirent *);
@@ -366,7 +365,6 @@ rmremote(void)
struct sigaction osa, nsa;

memset(&nsa, 0, sizeof(nsa));
- nsa.sa_handler = alarmer;
sigemptyset(&nsa.sa_mask);
nsa.sa_flags = 0;
(void)sigaction(SIGALRM, &nsa, &osa);
@@ -387,11 +385,6 @@ bad:
return;
}

-static void
-alarmer(int s)
-{
- /* nothing */
-}

/*
* Return 1 if the filename begins with 'cf'
Chris Bennett
2016-01-26 18:52:54 UTC
Permalink
Post by Chris Bennett
I found this in several other files in lpr src directories.
Doesn't seem to get used in any lp* files or connect with anything
higher up.
Am I looking at this correctly or way off?
It is used. Read up on sigaction(2) and alarm(3).
The high level explanation is in the first part of this commit message
from NetBSD
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.sbin/lpr/common_source/rmjob.c?rev=1.15&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
} else {
struct sigaction osa, nsa;
// initialize new sigaction structure nsa
// alarmer is the function to be executed
memset(&nsa, 0, sizeof(nsa));
nsa.sa_handler = alarmer;
sigemptyset(&nsa.sa_mask);
nsa.sa_flags = 0;
// install nsa to act on SIGALRM,
// save old sigact structure osa
(void)sigaction(SIGALRM, &nsa, &osa);
// raise sigalrm (execute alarmer, i.e., do nothing)
// after wait time seconds.
alarm(wait_time);
// if first write fails, bail out and inform admin of
// "Lost connection"
i = strlen(buf);
// try to write all of buf into rem
if (write(rem, buf, i) != i)
fatal("Lost connection");
// read rem and write it to stdout.
while ((i = read(rem, buf, sizeof(buf))) > 0)
(void)fwrite(buf, 1, i, stdout);
// turn current alarm off
alarm(0);
// re-install osa
(void)sigaction(SIGALRM, &osa, NULL);
// close rem
(void)close(rem);
}
I actually started to think I was wrong after I posted diff. Was reading
man pages about signals just now. I didn't know there was an alarm man
page, thanks. It looks like I need to rewrite code to use setitimer
since alarm is now obsolete.

Chris
Todd C. Miller
2016-01-26 22:16:42 UTC
Permalink
Post by Chris Bennett
I actually started to think I was wrong after I posted diff. Was reading
man pages about signals just now. I didn't know there was an alarm man
page, thanks. It looks like I need to rewrite code to use setitimer
since alarm is now obsolete.
Please don't, alarm(3) is perfectly fine to be using. We should
probably remove that line from the manual.

- todd
Theo Buehler
2016-01-26 23:04:43 UTC
Permalink
Post by Todd C. Miller
Please don't, alarm(3) is perfectly fine to be using. We should
probably remove that line from the manual.
The comment of alarm being made obsolete by setitimer has been there
for 30 years:

https://www.freebsd.org/cgi/man.cgi?query=alarm&apropos=0&sektion=0&manpath=2.10+BSD&arch=default&format=html

NetBSD and FreeBSD also still have it.

Index: alarm.3
===================================================================
RCS file: /var/cvs/src/lib/libc/gen/alarm.3,v
retrieving revision 1.13
diff -u -p -r1.13 alarm.3
--- alarm.3 17 Jul 2013 05:42:11 -0000 1.13
+++ alarm.3 26 Jan 2016 22:57:39 -0000
@@ -38,11 +38,6 @@
.Ft unsigned int
.Fn alarm "unsigned int seconds"
.Sh DESCRIPTION
-.Bf -symbolic
-This interface is made obsolete by
-.Xr setitimer 2 .
-.Ef
-.Pp
The
.Fn alarm
function waits a count of
Ingo Schwarze
2016-01-26 23:39:04 UTC
Permalink
Hi Theo,
Post by Theo Buehler
Post by Todd C. Miller
Please don't, alarm(3) is perfectly fine to be using. We should
probably remove that line from the manual.
The comment of alarm being made obsolete by setitimer has been there
https://www.freebsd.org/cgi/man.cgi?query=alarm&apropos=0&sektion=0&manpath=2.10+BSD&arch=default&format=html
NetBSD and FreeBSD also still have it.
I would prefer the following patch.

* Use the same wording up front as for ualarm(3).
It is relevant because alarm(3) and setitimer(ITIMER_REAL, ...)
cancel each other. Without that sentence, people might be misled
to think that they could use both to set independent alarms.

* There are so many cross references that the SEE ALSO section
looks confusing. Delete those that are not helpful:

- The XSI sigpause(3) is less portable than the POSIX sigsuspend(3)
and only minimally easier to use. POSIX calls sigpause(3)
obsolescent, we call it obsolete.
- The obsolete function sigvec(3) isn't standardized and less
powerful than the POSIX sigaction(3).
- The former XSI usleep(3) is less portable than the POSIX nanosleep(3)
and only minimally easier to use. Current POSIX does not even
mention usleep(3) as an XSI extension.
- We could add nanosleep(3), but it differs from alarm(3) in two
respects: Different granularity and not implemented by signal
delivery, so it is not all that relevant, and it is linked
from sleep(3) anyway.

* Update the POSIX reference while here.

* Also delete the misleading comment from the source file.

OK?
Ingo


Index: alarm.3
===================================================================
RCS file: /cvs/src/lib/libc/gen/alarm.3,v
retrieving revision 1.13
diff -u -p -r1.13 alarm.3
--- alarm.3 17 Jul 2013 05:42:11 -0000 1.13
+++ alarm.3 26 Jan 2016 23:37:05 -0000
@@ -39,7 +39,7 @@
.Fn alarm "unsigned int seconds"
.Sh DESCRIPTION
.Bf -symbolic
-This interface is made obsolete by
+This is a simplified interface to
.Xr setitimer 2 .
.Ef
.Pp
@@ -75,16 +75,14 @@ error code is placed in the global varia
.Xr setitimer 2 ,
.Xr sigaction 2 ,
.Xr signal 3 ,
-.Xr sigpause 3 ,
-.Xr sigvec 3 ,
+.Xr sigsuspend 3 ,
.Xr sleep 3 ,
-.Xr ualarm 3 ,
-.Xr usleep 3
+.Xr ualarm 3
.Sh STANDARDS
The
.Fn alarm
function conforms to
-.St -p1003.1-90 .
+.St -p1003.1-2008 .
.Sh HISTORY
An
.Fn alarm
Index: alarm.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/alarm.c,v
retrieving revision 1.7
diff -u -p -r1.7 alarm.c
--- alarm.c 8 Aug 2005 08:05:33 -0000 1.7
+++ alarm.c 26 Jan 2016 23:37:05 -0000
@@ -28,9 +28,6 @@
* SUCH DAMAGE.
*/

-/*
- * Backwards compatible alarm.
- */
#include <sys/time.h>
#include <unistd.h>
Post by Theo Buehler
Index: alarm.3
===================================================================
RCS file: /var/cvs/src/lib/libc/gen/alarm.3,v
retrieving revision 1.13
diff -u -p -r1.13 alarm.3
--- alarm.3 17 Jul 2013 05:42:11 -0000 1.13
+++ alarm.3 26 Jan 2016 22:57:39 -0000
@@ -38,11 +38,6 @@
.Ft unsigned int
.Fn alarm "unsigned int seconds"
.Sh DESCRIPTION
-.Bf -symbolic
-This interface is made obsolete by
-.Xr setitimer 2 .
-.Ef
-.Pp
The
.Fn alarm
function waits a count of
Todd C. Miller
2016-01-26 23:44:36 UTC
Permalink
Post by Ingo Schwarze
I would prefer the following patch.
* Use the same wording up front as for ualarm(3).
It is relevant because alarm(3) and setitimer(ITIMER_REAL, ...)
cancel each other. Without that sentence, people might be misled
to think that they could use both to set independent alarms.
OK.
Post by Ingo Schwarze
* There are so many cross references that the SEE ALSO section
- The XSI sigpause(3) is less portable than the POSIX sigsuspend(3)
and only minimally easier to use. POSIX calls sigpause(3)
obsolescent, we call it obsolete.
- The obsolete function sigvec(3) isn't standardized and less
powerful than the POSIX sigaction(3).
- The former XSI usleep(3) is less portable than the POSIX nanosleep(3)
and only minimally easier to use. Current POSIX does not even
mention usleep(3) as an XSI extension.
- We could add nanosleep(3), but it differs from alarm(3) in two
respects: Different granularity and not implemented by signal
delivery, so it is not all that relevant, and it is linked
from sleep(3) anyway.
OK.
Post by Ingo Schwarze
* Update the POSIX reference while here.
* Also delete the misleading comment from the source file.
OK.

I really just didn't want alarm(3) telling people to use setitimer(2)
when POSIX has deprecated setitimer(2) in favor of the timer_settime(2)
(which we don't support). Unlike setitimer(2), alarm(3) is set to
remain in POSIX for the forseeable future.

- todd
Theo Buehler
2016-01-26 23:48:08 UTC
Permalink
Post by Ingo Schwarze
Post by Theo Buehler
Post by Todd C. Miller
Please don't, alarm(3) is perfectly fine to be using. We should
probably remove that line from the manual.
The comment of alarm being made obsolete by setitimer has been there
https://www.freebsd.org/cgi/man.cgi?query=alarm&apropos=0&sektion=0&manpath=2.10+BSD&arch=default&format=html
NetBSD and FreeBSD also still have it.
I would prefer the following patch.
So do I. That's much better than the cheapest possible solution I
chose. I suggest to give others a chance to express their opinion, but
as far as I'm concerned this is ok.

Loading...