aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--tools/abcprintd.c22
-rw-r--r--tools/fileop.c19
2 files changed, 19 insertions, 22 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);
diff --git a/tools/fileop.c b/tools/fileop.c
index 268665e..d53c123 100644
--- a/tools/fileop.c
+++ b/tools/fileop.c
@@ -4,7 +4,6 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <alloca.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -15,7 +14,7 @@
# define O_BINARY 0
#endif
-const char *file_op_dir;
+bool fileops;
static ssize_t xwrite(int fd, const void *buf, size_t count)
{
@@ -114,32 +113,24 @@ static const char my_tolower[256] =
static void do_open(int fd, uint16_t ix, char *name)
{
- char *path, *p, *p0;
- int opl;
int i;
bool nodot;
struct file_data *fm;
int err;
static const char *modes[6] = {"r+t", "r+b", "w+t", "w+b", "rt", "rb" };
+ char path[16], *p;
name[11] = '\0';
- if (!file_op_dir) {
+ if (!fileops) {
send_reply(fd, 128+42); /* Skivan ej klar */
return;
}
do_close(-1, ix);
- opl = strlen(file_op_dir);
- path = alloca(opl+14);
- memcpy(path, file_op_dir, opl);
- p = path+opl;
- if (p[-1] != '/')
- *p++ = '/';
-
nodot = true;
- p0 = p;
+ p = path;
for (i = 0; i < 11; i++) {
if (name[i] != ' ') {
if (i >= 8 && nodot) {
@@ -150,7 +141,7 @@ static void do_open(int fd, uint16_t ix, char *name)
}
}
- if (p == p0) {
+ if (p == path) {
/* Empty filename */
send_reply(fd, 128+21); /* File not found */
return;