aboutsummaryrefslogtreecommitdiffstats
path: root/tools/abcprintd.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@trantor.hos.anvin.org>2009-01-18 17:32:38 -0800
committerH. Peter Anvin <hpa@trantor.hos.anvin.org>2009-01-18 17:32:38 -0800
commit5641f6a7415079cc43695f2d3fe2ba63a6c7dd17 (patch)
treea328d54fbaed3688bf45702a35ee4ead8c2ac569 /tools/abcprintd.c
parent0bbb0f26d29c19cfb44e8555b2101ec4a420c5b3 (diff)
downloadabc80-5641f6a7415079cc43695f2d3fe2ba63a6c7dd17.tar.gz
abc80-5641f6a7415079cc43695f2d3fe2ba63a6c7dd17.tar.xz
abc80-5641f6a7415079cc43695f2d3fe2ba63a6c7dd17.zip
abcprintd: fix the handing of path names
daemon() by default makes a chdir to /. We don't want that if we have a file directory. Furthermore, we can make the whole file directory handling a lot simpler if we chdir() to the file directory and then use plain filename paths.
Diffstat (limited to 'tools/abcprintd.c')
-rw-r--r--tools/abcprintd.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/abcprintd.c b/tools/abcprintd.c
index 4b4b610..a6e03b4 100644
--- a/tools/abcprintd.c
+++ b/tools/abcprintd.c
@@ -18,14 +18,15 @@
* Usage: abcprintd port [options to lpr]
*/
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
-#include <unistd.h>
-#include <termios.h>
#include <stdlib.h>
#include <string.h>
-#include <stdbool.h>
#include <sys/wait.h>
-#include <fcntl.h>
+#include <termios.h>
+#include <unistd.h>
#ifndef O_TEXT
# define O_TEXT 0
@@ -176,7 +177,7 @@ static void output(int c, FILE *tf, enum print_state *psp)
}
extern bool file_op(unsigned char, int);
-extern const char *file_op_dir;
+extern bool *fileops;
#define BUF_SIZE 4096
@@ -204,12 +205,17 @@ int main(int argc, char *argv[])
bool badopt = false;
speed_t speed = B115200;
- file_op_dir = NULL;
+ fileops = false;
while ((o = getopt(argc, argv, "d:t")) != EOF) {
switch (o) {
case 'd':
- file_op_dir = optarg;
+ if (chdir(optarg)) {
+ fprintf(stderr, "%s: chdir %s: %s\n",
+ argv[0], optarg, strerror(errno));
+ exit(1);
+ }
+ fileops = true;
break;
default:
badopt = true;
@@ -244,7 +250,7 @@ int main(int argc, char *argv[])
memcpy(lpr_argv, argv+optind+1, sizeof(char *)*(lpr_argc+1));
}
- daemon(0,0);
+ daemon(fileops,0);
print_setup(&tf, &ps);