summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Jon McCann <mccann@jhu.edu>2007-03-06 16:07:24 -0500
committerWilliam Jon McCann <mccann@jhu.edu>2007-03-06 16:07:24 -0500
commitdc5e9585215f34ec78b68fbb6da990a90d8f3a1b (patch)
treeed64be3c15a74a9f98083d2ad0bdf6bcc973caf7
parentce4ee7b54d40faf13e005285e5b85a061f21e256 (diff)
use paths.h if available
-rw-r--r--configure.ac2
-rw-r--r--pam-ck-connector/pam-ck-connector.c14
-rw-r--r--pam-ck-connector/test-pam.c8
-rw-r--r--src/ck-seat.c11
-rw-r--r--src/getfd.c28
-rw-r--r--src/proc-linux.c10
6 files changed, 58 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac
index 4cd3b58..796186f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,8 @@ GLIB_REQUIRED_VERSION=2.7.0
GDK_REQUIRED_VERSION=2.8.0
AC_CHECK_HEADERS(unistd.h)
+AC_CHECK_HEADERS(paths.h)
+
AC_TYPE_UID_T
AC_CHECK_FUNCS([setresuid setenv unsetenv clearenv])
diff --git a/pam-ck-connector/pam-ck-connector.c b/pam-ck-connector/pam-ck-connector.c
index 39c0332..5d4f7c0 100644
--- a/pam-ck-connector/pam-ck-connector.c
+++ b/pam-ck-connector/pam-ck-connector.c
@@ -26,6 +26,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+#include "config.h"
+
#include <ctype.h>
#include <pwd.h>
#include <stdarg.h>
@@ -39,6 +41,14 @@
#include <dirent.h>
#include <errno.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif /* HAVE_PATHS_H */
+
+#ifndef _PATH_DEV
+#define _PATH_DEV "/dev/"
+#endif
+
#define PAM_SM_SESSION
#include <security/pam_modules.h>
@@ -187,8 +197,8 @@ pam_sm_open_session (pam_handle_t *pamh,
if (strchr (display_device, ':') != NULL) {
x11_display = display_device;
display_device = "";
- } else if (strncmp ("/dev/", display_device, 5) != 0) {
- snprintf (ttybuf, sizeof (ttybuf), "/dev/%s", display_device);
+ } else if (strncmp (_PATH_DEV, display_device, 5) != 0) {
+ snprintf (ttybuf, sizeof (ttybuf), _PATH_DEV "%s", display_device);
display_device = ttybuf;
}
diff --git a/pam-ck-connector/test-pam.c b/pam-ck-connector/test-pam.c
index b5619b9..310a15f 100644
--- a/pam-ck-connector/test-pam.c
+++ b/pam-ck-connector/test-pam.c
@@ -24,6 +24,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -31,6 +33,10 @@
#include <security/pam_appl.h>
#include <security/pam_misc.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif /* HAVE_PATHS_H */
+
#define PAM_MAX_LOGIN_TRIES 3
#define PAM_FAIL_CHECK if (retcode != PAM_SUCCESS) { \
fprintf (stderr, "\n%s\n", pam_strerror (pamh, retcode)); \
@@ -69,7 +75,7 @@ main (int argc, char *argv[])
ttyn = ttyname (0);
- if (strncmp(ttyn, "/dev/", 5) == 0) {
+ if (strncmp (ttyn, _PATH_DEV, 5) == 0) {
tty_name = ttyn + 5;
} else {
tty_name = ttyn;
diff --git a/src/ck-seat.c b/src/ck-seat.c
index 033dc2d..c980ad5 100644
--- a/src/ck-seat.c
+++ b/src/ck-seat.c
@@ -25,6 +25,13 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif /* HAVE_PATHS_H */
+
+#ifndef _PATH_TTY
+#define _PATH_TTY "/dev/tty"
+#endif
#include <glib.h>
#include <glib/gi18n.h>
@@ -196,7 +203,7 @@ _seat_activate_session (CkSeat *seat,
ck_session_get_display_device (session, &device, NULL);
- if (device == NULL || (sscanf (device, "/dev/tty%u", &num) != 1)) {
+ if (device == NULL || (sscanf (device, _PATH_TTY "%u", &num) != 1)) {
GError *error;
error = g_error_new (CK_SEAT_ERROR,
CK_SEAT_ERROR_GENERAL,
@@ -480,7 +487,7 @@ update_active_vt (CkSeat *seat,
CkSession *session;
char *device;
- device = g_strdup_printf ("/dev/tty%u", num);
+ device = g_strdup_printf (_PATH_TTY "%u", num);
ck_debug ("Active device: %s", device);
diff --git a/src/getfd.c b/src/getfd.c
index 2ddcf01..69c37a3 100644
--- a/src/getfd.c
+++ b/src/getfd.c
@@ -1,15 +1,21 @@
/*
- * Copied from kbd-1.12
+ * Adapted from kbd-1.12
* License: GPL
*
*/
+#include "config.h"
+
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/kd.h>
#include <sys/ioctl.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif /* HAVE_PATHS_H */
+
/*
* getfd.c
*
@@ -24,7 +30,7 @@ is_a_console (int fd)
char arg;
arg = 0;
- return (ioctl(fd, KDGKBTYPE, &arg) == 0
+ return (ioctl (fd, KDGKBTYPE, &arg) == 0
&& ((arg == KB_101) || (arg == KB_84)));
}
@@ -33,10 +39,10 @@ open_a_console (char *fnam)
{
int fd;
- fd = open(fnam, O_RDONLY);
+ fd = open (fnam, O_RDONLY);
if (fd < 0 && errno == EACCES)
fd = open(fnam, O_WRONLY);
- if (fd < 0 || ! is_a_console(fd))
+ if (fd < 0 || ! is_a_console (fd))
return -1;
return fd;
}
@@ -45,16 +51,24 @@ int getfd (void)
{
int fd;
- fd = open_a_console("/dev/tty");
+ fd = open_a_console (_PATH_TTY);
+ if (fd >= 0)
+ return fd;
+
+ fd = open_a_console ("/dev/tty");
+ if (fd >= 0)
+ return fd;
+
+ fd = open_a_console (_PATH_CONSOLE);
if (fd >= 0)
return fd;
- fd = open_a_console("/dev/console");
+ fd = open_a_console ("/dev/console");
if (fd >= 0)
return fd;
for (fd = 0; fd < 3; fd++)
- if (is_a_console(fd))
+ if (is_a_console (fd))
return fd;
return -1;
diff --git a/src/proc-linux.c b/src/proc-linux.c
index 30e7d22..a247e75 100644
--- a/src/proc-linux.c
+++ b/src/proc-linux.c
@@ -28,6 +28,10 @@
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif /* HAVE_PATHS_H */
+
#include "proc.h"
/* adapted from procps */
@@ -107,7 +111,7 @@ load_drivers (void)
buf[bytes] = '\0';
p = buf;
- while ((p = strstr (p, " /dev/"))){
+ while ((p = strstr (p, " " _PATH_DEV))){
tty_map_node *tmn;
int len;
char *end;
@@ -188,7 +192,7 @@ driver_name (guint maj,
tmn = tmn->next;
}
- tty = g_strdup_printf ("/dev/%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */
+ tty = g_strdup_printf (_PATH_DEV "%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */
if (stat (tty, &sbuf) < 0){
g_free (tty);
@@ -196,7 +200,7 @@ driver_name (guint maj,
return NULL;
}
- tty = g_strdup_printf ("/dev/%s", tmn->name); /* like "/dev/ttyZZ255" */
+ tty = g_strdup_printf (_PATH_DEV "%s", tmn->name); /* like "/dev/ttyZZ255" */
if (stat (tty, &sbuf) < 0) {
g_free (tty);