* details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
* display manager
*/
+# include <sys/types.h>
# include <sys/signal.h>
# include <sys/stat.h>
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) && OSMAJORVERSION > 8
# include <utmpx.h>
#else
# include <utmp.h>
# include <time.h>
# include <utime.h>
# include <pwd.h>
-#if defined(linux) || defined(__FreeBSD__)
+#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
# include <stdarg.h>
#else
# include <varargs.h>
#define sigmask(m) (1 << (( m-1)))
#endif
-
-/***************************************************************************
- *
- * External variable declarations
- *
- ***************************************************************************/
-
-#if defined(USL) || defined(__uxp__)
-extern int makepttypair ();
-#endif
-
-
/***************************************************************************
*
* Local procedure declarations
static void TerminateProcess( int pid, int sig) ;
static void UnlockPidFile( void ) ;
static void dtMakeDefaultDir( void );
-static void dtmkdir(char *dir, mode_t dir_mode);
+static void dtmkdir(char *dir, mode_t dir_mode, int force);
if ( (progName = malloc(strlen(argv[0]) + 1)) != NULL )
strcpy(progName, argv[0]);
-#if defined(USL) || defined(__uxp__)
- /* create master slave pair for use in login */
- if (makepttypair () < 0)
- {
- Debug ("Could not create pty for use in login");
- exit (1);
- }
-#endif
-
/*
* Step 1 - load configuration parameters
ScanServers ();
StartDisplays ();
(void) signal (SIGHUP, RescanNotify);
-#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__uxp__)|| defined (__osf__) || defined(linux)
+#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__linux__)
(void) signal (SIGCHLD, ChildNotify);
#endif
while (AnyWellKnownSockets() || AnyDisplaysLeft ())
TrimErrorFile();
-#if defined(SYSV) && !defined(hpux) && !defined(_AIX) && !defined(__uxp__) && !defined (__osf__) && !defined(linux)
+#if defined(SYSV) && !defined(hpux) && !defined(_AIX) && !defined(__linux__)
WaitForChild ();
#else
WaitForSomething ();
LogError(
ReadCatalog(MC_LOG_SET,MC_LOG_NO_SRVACC,MC_DEF_LOG_NO_SRVACC),
servers);
- return;
+ return 0;
}
if (ServersModTime == 0)
{
{
ParseDisplay (servers, acceptableTypes, NumTypes, &puser);
}
+ return 1;
}
static void
int ChildReady = 0;
-#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__uxp__) || defined (__osf__) || defined(linux) || defined(CSRG_BASED)
+#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__linux__) || defined(CSRG_BASED)
static SIGVAL
ChildNotify( int arg )
{
Debug("Check %s: status=%d wakeupTime=%d\n", d->name,
d->status, wakeupTime);
if (d->status == suspended && wakeupTime >= 0)
- if ( GettyRunning(d) || (strcmp(d->gettyLine,"??") == 0))
+ if ( GettyRunning(d) || (d->gettyLine && (strcmp(d->gettyLine,"??") == 0)) )
if ( wakeupTime == 0 ) {
Debug("Polling of suspended server %s started.\n",
d->name);
*/
if (d->displayType.origin == FromFile && dt_shutdown ) {
RemoveDisplay(d);
- return;
+ return 0;
}
{
bkup[0] = '\0';
if (d->authFile)
- strcpy(bkup ,d->authFile);
+ snprintf(bkup, sizeof(bkup), "%s", d->authFile);
LoadDisplayResources (d);
kill (d->serverPid, d->resetSignal);
}
-#ifndef __apollo
/*
* initialize d->utmpId. Check to see if anyone else is using
* the requested ID. Always allow the first request for "dt" to
LogError ((unsigned char *)"All DT utmp IDs already in use. Removing display %s\n",
d->name);
RemoveDisplay(d);
- return;
+ return 0;
}
}
-#endif
/*
* set d->gettyLine to "console" for display ":0" if it is not
if (!StartGetty(d))
RemoveDisplay (d);
- return;
+ return 0;
}
}
else
p = DisplayName;
- strncpy(p, d->name, sizeof(DisplayName));
+ strncpy(p, d->name, sizeof(DisplayName) - 1);
DisplayName[sizeof(DisplayName)-1] = '\0';
if ( (s = strchr(p,':')) != NULL )
d->status = running;
break;
}
+ return 1;
}
static void
}
#endif
-CloseOnFork ()
+int
+CloseOnFork (void)
{
int fd;
close (fd);
FD_ZERO (&CloseMask);
max = 0;
+
+ return 0;
}
static int pidFd;
if (pidFd == -1 && errno == ENOENT)
{
/*
- * HP OSF/1 will not allow an fdopen
+ * A Legacy OS wouldn't allow an fdopen
* of a file descriptor handed back by creat(2).
* The workaround is to close the created file, and
* open it Read/Write. This will be transparent to HP-UX.
+ * This code needs to be cleaned up - 05/22/18 - C
*/
pidFd = creat (pidFile, 0644);
- close( pidFd );
+ if(pidFd != -1) {
+ close( pidFd );
+ }
pidFd = open (pidFile, 2);
}
if (pidFd == -1 || !(pidFilePtr = fdopen (pidFd, "r+")))
fclose (pidFilePtr);
}
-#ifdef oldcode
-/*VARARGS*/
-SetTitle (va_alist)
-va_dcl
-{
-#ifndef NOXDMTITLE
- char *p = Title;
- int left = TitleLen;
- char *s;
- va_list args;
-
- va_start(args);
- *p++ = '-';
- --left;
- while (s = va_arg (args, char *))
- {
- while (*s && left > 0)
- {
- *p++ = *s++;
- left--;
- }
- }
- while (left > 0)
- {
- *p++ = ' ';
- --left;
- }
- va_end(args);
-#endif
-}
-#endif
-
int
SetTitle( char *name, char *ptr )
{
* remove domain qualifiers and screens from name...
*/
- if ( (p = malloc(strlen(name) + 1)) == NULL) return;
+ if ( (p = malloc(strlen(name) + 1)) == NULL) return 0;
strcpy(p, name);
if ( (s = strchr(p,':')) == NULL ) {
free(p);
- return;
+ return 0;
}
if ( (t = strchr(s,'.')) != NULL )
free(p);
#endif
+ return 1;
}
*
*****************************************************************************/
-#if defined (_AIX) && defined (_POWER) || defined (__osf__)
+#if defined (_AIX) && defined (_POWER)
#define GETTYPATH "/usr/sbin/getty"
-#elif !defined (__apollo)
+#elif defined(__OpenBSD__)
+#define GETTYPATH "/usr/libexec/getty"
+#elif defined(__linux__)
+#define GETTYPATH "/sbin/getty"
+#else
#define GETTYPATH "/etc/getty"
#endif
FILE *tf;
char buf[128];
- strcpy(buf,"/dev/");
- strcat(buf,d->gettyLine);
+ if (quiet) return;
+
+ snprintf(buf, sizeof(buf), "/dev/%s", d->gettyLine);
if ( (tf = fopen (buf, "a")) != NULL) {
fprintf (tf,
switch (msgnum) {
case 1:
- fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_SUS1_LABEL,MC_DEF_SUS1_LABEL));
+ fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_SUS1_LABEL,MC_DEF_SUS1_LABEL));
- fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_SUS2_LABEL,MC_DEF_SUS2_LABEL));
+ fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_SUS2_LABEL,MC_DEF_SUS2_LABEL));
- fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_SUS3_LABEL,MC_DEF_SUS3_LABEL));
+ fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_SUS3_LABEL,MC_DEF_SUS3_LABEL));
break;
case 2:
- fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_RES_LABEL,MC_DEF_RES_LABEL));
+ fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_RES_LABEL,MC_DEF_RES_LABEL));
break;
(char *)ReadCatalog(MC_LABEL_SET,MC_START_LBLDPY,MC_DEF_START_LBLDPY),
d->name);
- fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_WAIT_LABEL,MC_DEF_WAIT_LABEL));
+ fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_WAIT_LABEL,MC_DEF_WAIT_LABEL));
break;
int
GettyRunning( struct display *d )
{
+#if defined(__FreeBSD__) && OSMAJORVERSION > 8
+ struct utmpx utmp; /* local struct for new entry */
+ struct utmpx *u; /* pointer to entry in utmp file */
+#else
struct utmp utmp; /* local struct for new entry */
struct utmp *u; /* pointer to entry in utmp file */
+#endif
int rvalue; /* return value (TRUE or FALSE) */
char buf[32];
return FALSE;
+#if defined(__FreeBSD__) && OSMAJORVERSION > 8
+ bzero(&utmp, sizeof(struct utmpx));
+#else
bzero(&utmp, sizeof(struct utmp));
+#endif
#ifdef _AIX
if (!strcmp(d->gettyLine,"console")) {
strcpy(utmp.ut_line,ttynm);
close(fd);
}
- else
- strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line));
+ else
+ {
+ strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line) - 1);
+ utmp.ut_line[sizeof(utmp.ut_line) - 1] = 0;
+ }
#else
- strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line));
+ strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line) - 1);
+ utmp.ut_line[sizeof(utmp.ut_line) - 1] = 0;
#endif
Debug("Checking for a getty on line %s.\n", utmp.ut_line);
static void
dtMakeDefaultDir( void )
{
- dtmkdir("/var", 0775);
- dtmkdir("/var/dt", 0755);
- dtmkdir("/var/dt/tmp", 0755);
- dtmkdir("/var/dt/appconfig", 0755);
- dtmkdir("/var/dt/appconfig/appmanager", 0755);
+ dtmkdir("/var", 0755, 0);
+ dtmkdir("/var/dt", 0755, 1);
+ dtmkdir("/var/dt/tmp", 0755, 1);
+ dtmkdir("/var/dt/appconfig", 0755, 1);
+ dtmkdir("/var/dt/appconfig/appmanager", 0755, 1);
}
static void
-dtmkdir(char *dir, mode_t dir_mode)
+dtmkdir(char *dir, mode_t dir_mode, int force)
{
struct stat file_status;
LogError((unsigned char *)"Unable to create dir %s\n", dir);
}
} else {
- if ( (file_status.st_mode & dir_mode) != dir_mode) {
+ if ( force && (file_status.st_mode & dir_mode) != dir_mode) {
/** try to set correct permissions **/
if ( chmod(dir, file_status.st_mode | dir_mode) == 0) {
Debug("Set permissions on %s\n", dir);