Bug 28620

Summary: [patch] install(1) has no way to pass options to strip
Product: Base System Reporter: Rob Braun <rbraun>
Component: binAssignee: ru <ru>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Rob Braun 2001-07-02 03:20:01 UTC
FreeBSD's xinstall [install(1)] lacks a way to pass arguments to strip.  In non-ELF systems this can be important.  Below is a patch to FreeBSD's xinstall TOT that adds a -Z flag that takes an argument that can be passed to strip(1) when it is exec'd.  It also lets the user specify an alternate strip program with the STRIP environment variable.  This functionality is based on NetBSD's xinstall -S flag.  Unfortunately, -S is already used by FreeBSD's xinstall as a "safe copy".

Fix: Here's the patch.  The note at the bottom of this page says not to submit code here, but provides no mechanism to do so.  If this is non functional, this patch was also submitted to the hackers list on Friday.




#ifdef __APPLE__
 u_long  string_to_flags __P((char **, u_long *, u_long *));
@@ -165,6 +166,12 @@
                case 'v':
                        verbose = 1;
                        break;
+               case 'Z':
+                       stripArgs = (char*)malloc(sizeof(char)*(strlen(optarg)+1
+));
+                       strcpy(stripArgs,optarg);
+                       dostrip = 1;
+                       break;
                case '?':
                default:
                        usage();
@@ -704,6 +711,7 @@
        char *to_name;
 {
        int serrno, status;
+       char *stripprog;

        switch (fork()) {
        case -1:
@@ -712,8 +720,19 @@
                errno = serrno;
                err(EX_TEMPFAIL, "fork");
        case 0:
-               execlp("strip", "strip", to_name, NULL);
-               err(EX_OSERR, "exec(strip)");
+               stripprog = getenv("STRIP");
+               if (stripprog == NULL)
+                       stripprog = _PATH_STRIP;
+               if (stripArgs) {
+                       char *cmd = (char*)malloc(sizeof(char)*
+                                               (3+strlen(stripprog)+
+                                               strlen(stripArgs)+
+                                               strlen(to_name)));
+                       sprintf(cmd, "%s %s %s", stripprog, stripArgs, to_name);
+                       execl(_PATH_BSHELL, "sh", "-c", cmd, NULL);
+               } else
+               execlp(stripprog, "strip", to_name, NULL);
+               err(EX_OSERR, "exec(%s)", stripprog);
        default:
                if (wait(&status) == -1 || status) {
                        (void)unlink(to_name);--0CqHvjnOHjmQEhvZ9oxIfUnffccPnAe9nVJlDDWVwQnoeTmv
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

Index: install.1
===================================================================
RCS file: /cvs/Darwin/Commands/BSD/file_cmds/install/install.1,v
retrieving revision 1.1.1.3
diff -u -d -r1.1.1.3 install.1
--- install.1   2001/06/28 00:35:04     1.1.1.3
+++ install.1   2001/06/30 19:45:52
@@ -46,6 +46,7 @@
 .Op Fl g Ar group
 .Op Fl m Ar mode
 .Op Fl o Ar owner
+.Op Fl Z Ar stripflags
 .Ar file1 file2
 .Nm
 .Op Fl bCcMpSsv
@@ -54,6 +55,7 @@
 .Op Fl g Ar group
 .Op Fl m Ar mode
 .Op Fl o Ar owner
+.Op Fl Z Ar stripflag
 .Ar file1 ... fileN directory
 .Nm
 .Fl d
@@ -61,6 +63,7 @@
 .Op Fl g Ar group
 .Op Fl m Ar mode
 .Op Fl o Ar owner
+.Op Fl Z Ar stripflag
 .Ar directory ...
 .Sh DESCRIPTION
 The file(s) are copied
@@ -155,6 +158,23 @@
 .Nm
 can be portable over a large
 number of systems and binary types.
+.It Fl Z Ar stripflags
+.Nm
+pases
+.Ar stripflags
+as option arguments to
+.Xr strip 1 .
+When -Z is used,
+.Xr strip 1
+is invoked via the
+.Xr sh 1
+shell, allowing a single -Z argument to be specified to
+.Nm
+which the shell can then tokenize.  Normally,
+.Nm
+invokes
+.Xr strip 1
+directly.  This flag implies -s
 .It Fl v
 Causes
 .Nm
Index: xinstall.c
===================================================================
RCS file: /cvs/Darwin/Commands/BSD/file_cmds/install/xinstall.c,v
retrieving revision 1.2
diff -u -d -r1.2 xinstall.c
--- xinstall.c  2001/06/28 00:38:03     1.2
+++ xinstall.c  2001/06/30 19:45:52
@@ -84,6 +84,7 @@
 int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose;
 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
 char *suffix = BACKUP_SUFFIX;
+char *stripArgs=NULL;
Comment 1 Mike Heffner freebsd_committer freebsd_triage 2001-07-02 05:36:10 UTC
Responsible Changed
From-To: freebsd-bugs->ru

Ruslan did the latest work on xinstall
Comment 2 ru freebsd_committer freebsd_triage 2004-06-11 14:56:54 UTC
Responsible Changed
From-To: ru->marcel

Marcel, could you please document the STRIPBIN envariable 
in the manpage, and then close this PR?
Comment 3 Marcel Moolenaar freebsd_committer freebsd_triage 2004-06-11 18:26:01 UTC
State Changed
From-To: open->closed
Comment 4 Marcel Moolenaar freebsd_committer freebsd_triage 2004-06-11 18:28:30 UTC
State Changed
From-To: closed->open

Grrr. Apparently GNATS doesn'y reject empty comments in an attempt 
to abort changing the state. Anyway: 
o  The STRIPBIN environment variable is documented, 
o  The PR is reassigned back to ru@ and kept open (well, is reopened 
again to be precise). 
The reason for not closing the PR is that we didn't implement a -Z 
option and there might actually be use for it. 



Comment 5 Marcel Moolenaar freebsd_committer freebsd_triage 2004-06-11 18:28:30 UTC
Responsible Changed
From-To: marcel->ru

Grrr. Apparently GNATS doesn'y reject empty comments in an attempt 
to abort changing the state. Anyway: 
o  The STRIPBIN environment variable is documented, 
o  The PR is reassigned back to ru@ and kept open (well, is reopened 
again to be precise). 
The reason for not closing the PR is that we didn't implement a -Z 
option and there might actually be use for it.
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2011-09-27 00:15:51 UTC
State Changed
From-To: open->closed

this is unlikely to happen