Bug#81040: queued fails to allocate ptys.
Package: queue
Version: 1.30.1-1
queued fails to allocate ptys correctly; it attempts to do this by
readdir'ing /dev and trying to find a free pty.
The enclosed patch converts it to use the Unix98 getpt etc. functions. The
patch isn't pretty & I've made no attempt to preserve the cross-platform
(HP-UX/Solaris etc.) functionality.
There is also a problem with the deallocpty function in pty.c; it attempts
to use a global variable which is only set-up in a child process (duh!). I
haven't attempted to fix that one.
Ralph.
--- queue-1.30.1.orig/handle.c
+++ queue-1.30.1/handle.c
@@ -844,8 +844,8 @@
fclose(temp);
exit(2);
}
- fchown(pty1, 0, 0);
- fchmod(pty1, S_IRUSR|S_IWUSR);
+/* fchown(pty1, 0, 0); */
+/* fchmod(pty1, S_IRUSR|S_IWUSR); */
}
}
dead = 0;
--- queue-1.30.1.orig/pty.c
+++ queue-1.30.1/pty.c
@@ -57,6 +57,17 @@
struct dirent *temp;
char *file, c;
+ fd = getpt();
+
+ if (fd >= 0 && grantpt (fd) >= 0 && unlockpt (fd) >= 0) {
+ line = ptsname (fd);
+ return fd;
+ }
+
+ if (fd >= 0)
+ close (fd);
+
+#if 0
#ifdef HAVE__GETPTY
/*IRIX*/
@@ -118,6 +129,7 @@
return(fd);
}
#endif /*HAVE__GETPTY*/
+#endif
syslog(LOG_ERR, "ptyalloc: no more ptys");
return (-1);
}
@@ -139,14 +151,27 @@
mkutmp(char *name, int pty2, int uid, int gid)
{
char *line;
- char buf[255];
+ char * shortline;
+
+ memset (&myu, 0, sizeof (struct utmp));
+
line = mtos();
- strcpy(myu.ut_user, name);
-#ifdef linux
- strncpy(myu.ut_id,line+8,2);
-#else
- strncpy(myu.ut_id, line+12,2);
-#endif
+
+ if (strncmp (line, "/dev/", 5) == 0)
+ line += 5;
+
+ shortline = line;
+ if (strncmp (shortline, "pts", 3) == 0)
+ shortline += 3;
+
+ if (strlen (shortline) > sizeof (myu.ut_id))
+ shortline += strlen (shortline) - sizeof (myu.ut_id);
+
+ strncpy (myu.ut_user, name, sizeof (myu.ut_user));
+ strncpy (myu.ut_id, shortline, sizeof (myu.ut_id));
+ strncpy (myu.ut_line, line, sizeof (myu.ut_line));
+
+#if 0
strcpy(buf, "/dev/tty");
strcat(buf, myu.ut_id);
#ifdef linux
@@ -154,26 +179,20 @@
#else
strcpy(myu.ut_line, line+9);
#endif
+#endif
+
myu.ut_pid = getpid();
myu.ut_type = USER_PROCESS;
myu.ut_time = time(NULL);
#ifdef HAVE_UT_ADDR
- strcpy(myu.ut_host, "Queue process");
+ strncpy(myu.ut_host, "Queue process", sizeof (myu.ut_host));
myu.ut_addr = 0L;
#endif
+
setutent();
getutid(&myu);
pututline(&myu);
- fchown(pty2, uid, gid);
- fchmod(pty2, S_IRUSR|S_IWUSR);
-
- if(!strcmp(buf,"/dev/tty")) {
- syslog(LOG_ERR,"queue: pty.c: mkutmp: bug: buf equals /dev/tty.");
- }
- else {
- chown(buf, uid, gid);
- chmod(buf, S_IRUSR|S_IWUSR);
- }
+ endutent();
}
/*HP ptsname is buggy! So we write our own!*/
@@ -184,14 +203,13 @@
static char buf[16];
register int i;
-#ifdef HAVE__GETPTY
+//#ifdef HAVE__GETPTY
if(line) return(line);
syslog(LOG_ERR, "mtos: call allocpty first.");
return(NULL);
-#else
-
+#if 0
ptym = buf2;
for(i=0;ptym[i]!=0;++i) if(ptym[i]=='/') {
ptym = &ptym[i+1];
Reply to: