delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/08/21/11:29:14

Message-ID: <39A14AC6.27459D60@softhome.net>
Date: Mon, 21 Aug 2000 17:29:10 +0200
From: Laurynas Biveinis <lauras AT softhome DOT net>
X-Mailer: Mozilla 4.74 [en] (Win98; U)
X-Accept-Language: lt,en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Patch: symlinks to programs
References: <39A1181F DOT C25823B3 AT softhome DOT net> <9791-Mon21Aug2000174639+0300-eliz AT is DOT elta DOT co DOT il>
Reply-To: djgpp-workers AT delorie DOT com

Eli Zaretskii wrote:
> I have one request: when sending non-trivial diffs for complex
> sources, please say "diff -up" or "diff -cp": this causes Diff to
> print the function name with each hunk, which makes the diffs much
> easier to understand.

OK.

> > -  argv[0] = unconst(program, char *); /* since that's where we really found it */
> > +  argv[0] = unconst(program, char *);
> 
> Please don't remove existing comments unless you have a very good
> reason for that.

I've removed this comment, because `program' does not mean 'where we _really_ found
it' now; it might be a symlink. Is it OK?

> > RCS file: args.c
> > diff -N args.c

> You didn't really mean that, did you?

You mean, addition of this file, right? It was added on purpose:
it is used together with testsuite:

symlink("args.exe", "linkargs.exe");
...
system("linkargs.exe 4 5 6");


> One thing that should be tested is when the symlink is not in the
> current directory, but along the PATH.  I don't think the above tests
> this situation, does it?

It doesn't. But it's not too hard to add.
Below is 'diff -p' for dosexec.c and testsuite addition for PATH.
Other parts of patch are the same.

Any comments?
Laurynas

Index: dosexec.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/dos/process/dosexec.c,v
retrieving revision 1.9
diff -u -p -r1.9 dosexec.c
--- dosexec.c	2000/08/03 12:21:17	1.9
+++ dosexec.c	2000/08/21 15:26:09
@@ -22,6 +22,7 @@
 #include <libc/unconst.h>
 #include <libc/dosio.h>
 #include <libc/farptrgs.h>
+#include <libc/symlink.h>
 
 /* FIXME: this is not LFN-clean.  Win95 has a way to
    pass long command lines, but we don't support it here.  */
@@ -519,6 +520,7 @@ static int go32_exec(const char *program
   int i;
   char *go32, *sip=0;
   char rpath[FILENAME_MAX];
+  char real_program[FILENAME_MAX];
   int argc=0;
 
   int si_la=0, si_off=0, rm_off, argv_off;
@@ -527,8 +529,11 @@ static int go32_exec(const char *program
   int retval;
   int lfn = 2;	/* means don't know yet */
 
-  type = _check_v2_prog (program, -1);
+  if (!__solve_symlinks(program, real_program))
+     return -1;
 
+  type = _check_v2_prog (real_program, -1);
+
   /* Because this function is called only, when program
      exists, I can skip the check for type->valid */
 
@@ -539,16 +544,16 @@ static int go32_exec(const char *program
 
   if (type->exec_format == _V2_EXEC_FORMAT_UNIXSCRIPT)
   {
-    return script_exec(program, argv, envp);
+    return script_exec(real_program, argv, envp);
   }
 
   /* Non-DJGPP programs cannot be run by !proxy.  */
   if (!is_coff)
   {
     if (type->exec_format == _V2_EXEC_FORMAT_EXE)
-      return direct_exec(program, argv, envp);
+      return direct_exec(real_program, argv, envp);
     else
-      return __dosexec_command_exec (program, argv, envp);
+      return __dosexec_command_exec (real_program, argv, envp);
   }
 
   if (found_si)
@@ -560,7 +565,7 @@ static int go32_exec(const char *program
 
   if (v2_0 && is_stubbed)
   {
-    strcpy(rpath, program);
+    strcpy(rpath, real_program);
   }
   else
   {
@@ -568,7 +573,7 @@ static int go32_exec(const char *program
     if (!__dosexec_find_on_path(go32, envp, rpath))
     {
       errno = e;
-      return direct_exec(program, argv, envp); /* give up and just run it */
+      return direct_exec(real_program, argv, envp); /* give up and just run it */
     }
 
     if (found_si)
@@ -586,7 +591,7 @@ static int go32_exec(const char *program
      usual DOS command line and the !proxy one (which will be put
      into the environment).  Sigh...  */
   save_argv0 = argv[0];
-  argv[0] = unconst(program, char *); /* since that's where we really found it */
+  argv[0] = unconst(program, char *);
   /* Construct the DOS command tail */
   for (argc=0; argv[argc]; argc++);
 
@@ -704,9 +709,13 @@ __dosexec_command_exec(const char *progr
   int cmdlen;
   int i;
   int was_quoted = 0;	/* was the program name quoted? */
+  char real_program[FILENAME_MAX];
+
+  if (!__solve_symlinks(program, real_program))
+     return -1;
 
   /* Add spare space for possible quote characters.  */
-  cmdlen = strlen(program) + 4 + 2;
+  cmdlen = strlen(real_program) + 4 + 2;
   for (i=0; argv[i]; i++)
     cmdlen += 2*strlen(argv[i]) + 1;
   cmdline = (char *)alloca(cmdlen);
@@ -714,21 +723,21 @@ __dosexec_command_exec(const char *progr
   /* FIXME: is this LFN-clean?  What special characters can
      the program name have and how should they be quoted?  */
   strcpy(cmdline, "/c ");
-  if (strchr(program, ' ') || strchr(program, '\t'))
+  if (strchr(real_program, ' ') || strchr(real_program, '\t'))
   {
     was_quoted = 1;
     cmdline[3] = '"';
   }
-  for (i = 0; program[i] > ' '; i++)
+  for (i = 0; real_program[i] > ' '; i++)
   {
     /* COMMAND.COM cannot grok program names with forward slashes.  */
     if (program[i] == '/')
       cmdline[i+3+was_quoted] = '\\';
     else
-      cmdline[i+3+was_quoted] = program[i];
+      cmdline[i+3+was_quoted] = real_program[i];
   }
-  for (; program[i]; i++)
-    cmdline[i+3+was_quoted] = program[i];
+  for (; real_program[i]; i++)
+    cmdline[i+3+was_quoted] = real_program[i];
   if (was_quoted)
   {
     cmdline[i+3+was_quoted] = '"';

Index: symlinks.c
===================================================================
RCS file: symlinks.c
diff -N symlinks.c
--- /dev/null	Tue May  5 16:32:27 1998
+++ symlinks.c	Mon Aug 21 11:27:11 2000
@@ -0,0 +1,31 @@
+/* Testsuite for symlink handling aspect in launching program. 
+ * This is by no means a regression testsuite, you have to decide 
+ * if bad stuff happens from output. 
+ *
+ * Shell script handling will be checked only if you have bash installed.
+ */
+#include <process.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(void)
+{
+   symlink("args.exe", "linkargs.exe");
+   system("args.exe 1 2 3");
+   system("linkargs.exe 4 5 6");
+   spawnl(P_WAIT, "args.exe", "args.exe", "what", NULL);
+   spawnl(P_WAIT, "linkargs.exe", "linkargs.exe", "where", "why", NULL);
+   remove("linkargs.exe");
+   symlink("C:/command.com", "linkcom.com");
+   system("linkcom.com");
+   remove("linkcom.com");
+   symlink("test.sh", "linksh.sh");
+   system("test.sh");
+   system("linksh.sh");
+   remove("linksh.sh");
+   symlink("/dev/env/DJDIR/bin/ls.exe", "/dev/env/DJDIR/bin/sl.exe");
+   system("sl -l");
+   remove("/dev/env/DJDIR/bin/sl.exe");
+   return 0;
+}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019