File: wrapns.c.in

package info (click to toggle)
netscape4.77 4.77-2
  • links: PTS
  • area: non-free
  • in suites: potato, woody
  • size: 27,132 kB
  • ctags: 63
  • sloc: sh: 1,927; makefile: 319
file content (64 lines) | stat: -rw-r--r-- 1,598 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * In sh, $0 is the argument passed to the #! program.
 * In perl and C, argv[0] is the name the program was called.
 * This program allows something to get both.
 * ...sigh... somewhat.
 * The kernel (Linux) doesn't pass along argv[0] to a script's interpreter. :(
 */

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <unistd.h>

static char *my_name = "${BIN}-${FLA}-${VERS}";
static char *script = "/usr/lib/netscape/base-4/wrapper";

int main ( int argc, char *argv[] )
{
	if ( !getenv( "NS_W_CALLED" ) ) {
		/* this is us being called initially, pass info along
		 * to script
		 */
		char *param;

		param = malloc( 11 + 1 + strlen( argv[0] ) + 1 );
		sprintf( param, "NS_W_CALLED=%s", argv[0] );
		putenv( param );

		param = malloc( 9 + 1 + strlen( my_name ) + 1 );
		sprintf( param, "NS_W_NAME=%s", my_name );
		putenv( param );

		execv( script, argv );
	} else if ( argc >= 3 ) {
		/* this is us being called from the script to execute the
		 * netscape binary.  Just call it, setting argv[0].
		 */
		char *preload;
		char **arg;
		int i;

		if ( ( preload = getenv( "NS_W_PRELOAD" ) ) != NULL ) {
			char *ldpreload;

			ldpreload = malloc( strlen( preload ) + 11 + 1 );
			sprintf( ldpreload, "LD_PRELOAD=%s", preload );
			putenv( ldpreload );
			unsetenv( "NS_W_PRELOAD" );
		}
		unsetenv( "NS_W_CALLED" );
		unsetenv( "NS_W_NAME" );

		arg = malloc( sizeof( *arg ) * (argc) );

		for ( i = 0 ; i < argc-2 ; i++ ) {
			arg[i] = argv[i+2];
		}
		arg[i] = NULL;

		execv( argv[1], arg );
	}
	fprintf( stderr, "%s: unknown parameters\n", argv[0] );
	return 1;
}