Commit 14333ef1 authored by William Jon McCann's avatar William Jon McCann Committed by William Jon McCann

Remove lots of obsolete code. Organize the configure checks a bit.

2007-10-04  William Jon McCann  <mccann@jhu.edu>

	* common/Makefile.am:
	* common/gdm-common.c:
	* common/gdm-common.h:
	* common/ve-signal.c:
	* common/ve-signal.h:
	* config/Makefile.am:
	* configure.ac:
	* daemon/Makefile.am:
	* daemon/auth.c:
	* daemon/filecheck.c:
	* daemon/filecheck.h:
	* daemon/gdm-factory-slave.c: (get_script_environment):
	* daemon/gdm-greeter-session.c: (get_greeter_environment):
	* daemon/gdm-product-slave.c: (get_script_environment):
	* daemon/gdm-server.c: (rotate_logs), (server_child_setup),
	(gdm_server_start):
	* daemon/gdm-simple-slave.c: (get_script_environment):
	* daemon/gdm-xdmcp-display-factory.c: (fd_set_close_on_exec),
	(open_port), (gdm_xdmcp_handle_request), (gdm_xdmcp_handle_manage):
	* libgreeter/Makefile.am:
	* libgreeter/gdmlanguages.c:
	* libgreeter/gdmlanguages.h:
	* libgreeter/gdmsession.c:
	* libgreeter/gdmsession.h:
	* libgreeter/gdmwm.c:
	* libgreeter/gdmwm.h:
	* utils/Makefile.am:
	* utils/gdm-ssh-session:
	* utils/gdmmktemp.c:
	* utils/gdmopen.c:
	* utils/gdmprefetch.c:
	* utils/gdmsetup-pam:
	* utils/gdmsetup-security.in:
	* utils/gdmtranslate.c:
	Remove lots of obsolete code.  Organize the configure checks a bit.


svn path=/branches/mccann-gobject/; revision=5339
parent dae89542
2007-10-04 William Jon McCann <mccann@jhu.edu>
* common/Makefile.am:
* common/gdm-common.c:
* common/gdm-common.h:
* common/ve-signal.c:
* common/ve-signal.h:
* config/Makefile.am:
* configure.ac:
* daemon/Makefile.am:
* daemon/auth.c:
* daemon/filecheck.c:
* daemon/filecheck.h:
* daemon/gdm-factory-slave.c: (get_script_environment):
* daemon/gdm-greeter-session.c: (get_greeter_environment):
* daemon/gdm-product-slave.c: (get_script_environment):
* daemon/gdm-server.c: (rotate_logs), (server_child_setup),
(gdm_server_start):
* daemon/gdm-simple-slave.c: (get_script_environment):
* daemon/gdm-xdmcp-display-factory.c: (fd_set_close_on_exec),
(open_port), (gdm_xdmcp_handle_request), (gdm_xdmcp_handle_manage):
* libgreeter/Makefile.am:
* libgreeter/gdmlanguages.c:
* libgreeter/gdmlanguages.h:
* libgreeter/gdmsession.c:
* libgreeter/gdmsession.h:
* libgreeter/gdmwm.c:
* libgreeter/gdmwm.h:
* utils/Makefile.am:
* utils/gdm-ssh-session:
* utils/gdmmktemp.c:
* utils/gdmopen.c:
* utils/gdmprefetch.c:
* utils/gdmsetup-pam:
* utils/gdmsetup-security.in:
* utils/gdmtranslate.c:
Remove lots of obsolete code. Organize the configure checks a bit.
2007-10-04 William Jon McCann <mccann@jhu.edu>
* acinclude.m4:
......
......@@ -70,8 +70,6 @@ libgdmcommon_la_SOURCES = \
gdm-md5.c \
gdm-signal-handler.h \
gdm-signal-handler.c \
ve-signal.h \
ve-signal.c \
$(NULL)
libgdmcommon_la_CPPFLAGS = \
......
......@@ -2,6 +2,7 @@
*
* (c) 2000 Eazel, Inc.
* (c) 2001,2002 George Lebl
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -42,188 +43,6 @@
#include "gdm-common.h"
#include "gdm-md5.h"
int
gdm_fdgetc (int fd)
{
char buf[1];
int bytes;
VE_IGNORE_EINTR (bytes = read (fd, buf, 1));
if (bytes != 1)
return EOF;
else
return (int)buf[0];
}
char *
gdm_fdgets (int fd)
{
int c;
int bytes = 0;
GString *gs = g_string_new (NULL);
for (;;) {
c = gdm_fdgetc (fd);
if (c == '\n')
return g_string_free (gs, FALSE);
/* on EOF */
if (c < 0) {
if (bytes == 0) {
g_string_free (gs, TRUE);
return NULL;
} else {
return g_string_free (gs, FALSE);
}
} else {
bytes++;
g_string_append_c (gs, c);
}
}
}
void
gdm_fdprintf (int fd, const gchar *format, ...)
{
va_list args;
gchar *s;
int written, len;
va_start (args, format);
s = g_strdup_vprintf (format, args);
va_end (args);
len = strlen (s);
if (len == 0) {
g_free (s);
return;
}
written = 0;
while (written < len) {
int w;
VE_IGNORE_EINTR (w = write (fd, &s[written], len - written));
if (w < 0)
/* evil! */
break;
written += w;
}
g_free (s);
}
void
gdm_close_all_descriptors (int from, int except, int except2)
{
DIR *dir;
struct dirent *ent;
GSList *openfds = NULL;
/*
* Evil, but less evil then going to _SC_OPEN_MAX
* which can be very VERY large
*/
dir = opendir ("/proc/self/fd/"); /* This is the Linux dir */
if (dir == NULL)
dir = opendir ("/dev/fd/"); /* This is the FreeBSD dir */
if G_LIKELY (dir != NULL) {
GSList *li;
while ((ent = readdir (dir)) != NULL) {
int fd;
if (ent->d_name[0] == '.')
continue;
fd = atoi (ent->d_name);
if (fd >= from && fd != except && fd != except2)
openfds = g_slist_prepend (openfds, GINT_TO_POINTER (fd));
}
closedir (dir);
for (li = openfds; li != NULL; li = li->next) {
int fd = GPOINTER_TO_INT (li->data);
VE_IGNORE_EINTR (close (fd));
}
g_slist_free (openfds);
} else {
int i;
int max = sysconf (_SC_OPEN_MAX);
/*
* Don't go higher then this. This is
* a safety measure to not hang on crazy
* systems
*/
if G_UNLIKELY (max > 4096) {
/* FIXME: warn about this perhaps */
/*
* Try an open, in case we're really
* leaking fds somewhere badly, this
* should be very high
*/
i = gdm_open_dev_null (O_RDONLY);
max = MAX (i+1, 4096);
}
for (i = from; i < max; i++) {
if G_LIKELY (i != except && i != except2)
VE_IGNORE_EINTR (close (i));
}
}
}
void
gdm_signal_ignore (int signal)
{
struct sigaction ign_signal;
ign_signal.sa_handler = SIG_IGN;
ign_signal.sa_flags = SA_RESTART;
sigemptyset (&ign_signal.sa_mask);
if G_UNLIKELY (sigaction (signal, &ign_signal, NULL) < 0)
g_warning (_("%s: Error setting signal %d to %s"),
"gdm_signal_ignore", signal, "SIG_IGN");
}
void
gdm_signal_default (int signal)
{
struct sigaction def_signal;
def_signal.sa_handler = SIG_DFL;
def_signal.sa_flags = SA_RESTART;
sigemptyset (&def_signal.sa_mask);
if G_UNLIKELY (sigaction (signal, &def_signal, NULL) < 0)
g_warning (_("%s: Error setting signal %d to %s"),
"gdm_signal_ignore", signal, "SIG_DFL");
}
int
gdm_open_dev_null (mode_t mode)
{
int ret;
VE_IGNORE_EINTR (ret = open ("/dev/null", mode));
if G_UNLIKELY (ret < 0) {
/*
* Never output anything, we're likely in some
* strange state right now
*/
gdm_signal_ignore (SIGPIPE);
VE_IGNORE_EINTR (close (2));
g_error ("Cannot open /dev/null, system on crack!");
}
return ret;
}
char *
gdm_make_filename (const char *dir,
const char *name,
const char *extension)
{
char *base = g_strconcat (name, extension, NULL);
char *full = g_build_filename (dir, base, NULL);
g_free (base);
return full;
}
static int sigchld_blocked = 0;
static sigset_t sigchldblock_mask, sigchldblock_oldmask;
......@@ -317,80 +136,33 @@ gdm_sigusr2_block_pop (void)
/* Like fopen with "w" */
FILE *
gdm_safe_fopen_w (const char *file, mode_t perm)
gdm_safe_fopen_w (const char *file,
mode_t perm)
{
int fd;
FILE *ret;
VE_IGNORE_EINTR (g_unlink (file));
do {
int flags;
errno = 0;
fd = open (file, O_EXCL|O_CREAT|O_TRUNC|O_WRONLY
flags = O_EXCL | O_CREAT | O_TRUNC | O_WRONLY;
#ifdef O_NOCTTY
|O_NOCTTY
flags |= O_NOCTTY;
#endif
#ifdef O_NOFOLLOW
|O_NOFOLLOW
flags |= O_NOFOLLOW;
#endif
, perm);
} while G_UNLIKELY (errno == EINTR);
if (fd < 0)
return NULL;
VE_IGNORE_EINTR (ret = fdopen (fd, "w"));
return ret;
}
/* Like fopen with "a+" */
FILE *
gdm_safe_fopen_ap (const char *file, mode_t perm)
{
int fd;
FILE *ret;
fd = g_open (file, flags, perm);
} while (errno == EINTR);
if (g_access (file, F_OK) == 0) {
do {
errno = 0;
fd = open (file, O_APPEND|O_RDWR
#ifdef O_NOCTTY
|O_NOCTTY
#endif
#ifdef O_NOFOLLOW
|O_NOFOLLOW
#endif
);
} while G_UNLIKELY (errno == EINTR);
} else {
/* Doesn't exist, open with O_EXCL */
do {
errno = 0;
fd = open (file, O_EXCL|O_CREAT|O_RDWR
#ifdef O_NOCTTY
|O_NOCTTY
#endif
#ifdef O_NOFOLLOW
|O_NOFOLLOW
#endif
, perm);
} while G_UNLIKELY (errno == EINTR);
}
if (fd < 0)
if (fd < 0) {
return NULL;
VE_IGNORE_EINTR (ret = fdopen (fd, "a+"));
return ret;
}
void
gdm_fd_set_close_on_exec (int fd)
{
int flags;
flags = fcntl (fd, F_GETFD, 0);
if (flags < 0) {
return;
}
flags |= FD_CLOEXEC;
fcntl (fd, F_SETFD, flags);
ret = fdopen (fd, "w");
return ret;
}
/**
......@@ -420,151 +192,7 @@ ve_clearenv (void)
#endif
}
char *
ve_first_word (const char *s)
{
int argc;
char **argv;
char *ret;
if (s == NULL)
return NULL;
if ( ! g_shell_parse_argv (s, &argc, &argv, NULL)) {
char *p;
ret = g_strdup (s);
p = strchr (ret, ' ');
if (p != NULL)
*p = '\0';
return ret;
}
ret = g_strdup (argv[0]);
g_strfreev (argv);
return ret;
}
static gboolean
ve_first_word_executable (const char *s,
gboolean only_existance)
{
char *bin = ve_first_word (s);
if (bin == NULL)
return FALSE;
if (g_access (bin, only_existance ? F_OK : X_OK) == 0) {
g_free (bin);
return TRUE;
} else {
g_free (bin);
return FALSE;
}
}
char *
ve_get_first_working_command (const char *list,
gboolean only_existance)
{
int i;
char **vector;
char *ret = NULL;
if (list == NULL)
return NULL;
vector = g_strsplit (list, ";", -1);
for (i = 0; vector[i] != NULL; i++) {
if (ve_first_word_executable (vector[i],
only_existance)) {
ret = g_strdup (vector[i]);
break;
}
}
g_strfreev (vector);
return ret;
}
char *
ve_locale_to_utf8 (const char *str)
{
char *ret = g_locale_to_utf8 (str, -1, NULL, NULL, NULL);
if (ret == NULL) {
g_warning ("string not in proper locale encoding: \"%s\"", str);
return g_strdup (str);
} else {
return ret;
}
}
char *
ve_locale_from_utf8 (const char *str)
{
char *ret = g_locale_from_utf8 (str, -1, NULL, NULL, NULL);
if (ret == NULL) {
g_warning ("string not in proper utf8 encoding: \"%s\"", str);
return g_strdup (str);
} else {
return ret;
}
}
char *
ve_filename_to_utf8 (const char *str)
{
char *ret = g_filename_to_utf8 (str, -1, NULL, NULL, NULL);
if (ret == NULL) {
g_warning ("string not in proper locale encoding: \"%s\"", str);
return g_strdup (str);
} else {
return ret;
}
}
char *
ve_filename_from_utf8 (const char *str)
{
char *ret = g_filename_from_utf8 (str, -1, NULL, NULL, NULL);
if (ret == NULL) {
g_warning ("string not in proper utf8 encoding: \"%s\"", str);
return g_strdup (str);
} else {
return ret;
}
}
pid_t
ve_waitpid_no_signal (pid_t pid, int *status, int options)
{
pid_t ret;
for (;;) {
ret = waitpid (pid, status, options);
if (ret == 0)
return 0;
if (errno != EINTR)
return ret;
}
}
gboolean
ve_locale_exists (const char *loc)
{
gboolean ret;
char *old = g_strdup (setlocale (LC_MESSAGES, NULL));
if (setlocale (LC_MESSAGES, loc) != NULL)
ret = TRUE;
else
ret = FALSE;
setlocale (LC_MESSAGES, old);
g_free (old);
return ret;
}
/* hex conversion adapted from D-Bus */
/**
* Appends a two-character hex digit to a string, where the hex digit
* has the value of the given byte.
......
......@@ -2,6 +2,7 @@
*
* (c) 2000 Eazel, Inc.
* (c) 2001,2002 George Lebl
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -28,16 +29,9 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <locale.h>
#include <netdb.h>
#include "ve-signal.h"
G_BEGIN_DECLS
#define ve_string_empty(x) ((x)==NULL||(x)[0]=='\0')
#define ve_sure_string(x) ((x)!=NULL?(x):"")
#define VE_IGNORE_EINTR(expr) \
do { \
errno = 0; \
......@@ -78,9 +72,6 @@ G_BEGIN_DECLS
/* like fopen with "w" but unlinks and uses O_EXCL */
FILE * gdm_safe_fopen_w (const char *file,
mode_t perm);
/* like fopen with "a+" and uses O_EXCL and O_NOFOLLOW */
FILE * gdm_safe_fopen_ap (const char *file,
mode_t perm);
/* This is for race free forks */
void gdm_sigchld_block_push (void);
......@@ -90,48 +81,7 @@ void gdm_sigterm_block_pop (void);
void gdm_sigusr2_block_push (void);
void gdm_sigusr2_block_pop (void);
void gdm_fdprintf (int fd, const gchar *format, ...) G_GNUC_PRINTF (2, 3);
int gdm_fdgetc (int fd);
char *gdm_fdgets (int fd);
void gdm_fd_set_close_on_exec (int fd);
void gdm_signal_ignore (int signal);
void gdm_signal_default (int signal);
void gdm_close_all_descriptors (int from, int except, int except2);
int gdm_open_dev_null (mode_t mode);
/* somewhat like g_build_filename, but does somet hing like
* <dir> "/" <name> <extension>
*/
char * gdm_make_filename (const char *dir,
const char *name,
const char *extension);
void ve_clearenv (void);
char * ve_first_word (const char *s);
/* Gets the first existing command out of a list separated by semicolons */
char * ve_get_first_working_command (const char *list,
gboolean only_existance);
/* These two functions will ALWAYS return a non-NULL string,
* if there is an error, they return the unconverted string */
char * ve_locale_to_utf8 (const char *str);
char * ve_locale_from_utf8 (const char *str);
/* These two functions will ALWAYS return a non-NULL string,
* if there is an error, they return the unconverted string */
char * ve_filename_to_utf8 (const char *str);
char * ve_filename_from_utf8 (const char *str);
/* function which doesn't stop on signals */
pid_t ve_waitpid_no_signal (pid_t pid, int *status, int options);
/* Testing for existance of a certain locale */
gboolean ve_locale_exists (const char *loc);
gboolean gdm_generate_random_bytes (GString *str,
int n_bytes);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Signal routines
*
* (c) 2000, 2002 Queen of England
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
#include <glib/gi18n.h>
#include "ve-signal.h"
typedef struct _SignalSource SignalSource;
struct _SignalSource {
GSource source;
int signal;
guint8 index;
guint8 shift;
};
static guint32 signals_notified[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
static gboolean
ve_signal_prepare (GSource *source,
int *timeout)
{
SignalSource *ss = (SignalSource *)source;
return signals_notified[ss->index] & (1 << ss->shift);
}
static gboolean
ve_signal_check (GSource *source)
{
SignalSource *ss = (SignalSource *)source;
return signals_notified[ss->index] & (1 << ss->shift);
}
static gboolean
ve_signal_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
SignalSource *ss = (SignalSource *)source;
signals_notified[ss->index] &= ~(1 << ss->shift);
return ((VeSignalFunc)callback) (ss->signal, user_data);
}
static GSourceFuncs signal_funcs = {
ve_signal_prepare,
ve_signal_check,
ve_signal_dispatch
};
guint
ve_signal_add (int signal,
VeSignalFunc function,
gpointer data)
{
return ve_signal_add_full (G_PRIORITY_DEFAULT, signal, function, data, NULL);
}
guint
ve_signal_add_full (int priority,
int signal,
VeSignalFunc function,
gpointer data,
GDestroyNotify destroy)
{
GSource *source;
SignalSource *ss;
guint s = 128 + signal;
g_return_val_if_fail (function != NULL, 0);
source = g_source_new (&signal_funcs, sizeof (SignalSource));
ss = (SignalSource *)source;
ss->signal = signal;
ss->index = s / 32;
ss->shift = s % 32;
g_assert (ss->index < 8);
g_source_set_priority (source, priority);
g_source_set_callback (source, (GSourceFunc)function, data, destroy);
g_source_set_can_recurse (source, TRUE);
return g_source_attach (source, NULL);
}
void
ve_signal_notify (int signal)
{
guint index, shift;
guint s = 128 + signal;
index = s / 32;
shift = s % 32;
g_assert (index < 8);
signals_notified[index] |= 1 << shift;
g_main_context_wakeup (NULL);
}
gboolean
ve_signal_was_notified (int signal)
{
guint index, shift;
guint s = 128 + signal;
index = s / 32;
shift = s % 32;
g_assert (index < 8);
return ((signals_notified[index]) & (1 << shift)) ? TRUE : FALSE;
}
void
ve_signal_unnotify (int signal)
{
guint index, shift;
guint s = 128 + signal;
index = s / 32;
shift = s % 32;
g_assert (index < 8);
signals_notified[index] &= ~(1 << shift);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Signal routines