summaryrefslogtreecommitdiff
path: root/net/net-snmp/patches/patch-ab
blob: 9c22ae140b8e92c70fe5a820a3b819a773ee4cb1 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
$NetBSD: patch-ab,v 1.4.6.1 2005/05/27 14:02:23 salo Exp $

--- local/fixproc.orig	2002-04-20 08:30:13.000000000 +0100
+++ local/fixproc	2005-05-25 14:36:18.000000000 +0100
@@ -129,6 +129,8 @@
 #
 # Timothy Kong		3/1995
 
+use File::Temp qw(tempfile);
+
 $database_file = '/local/etc/fixproc.conf';
 
 $debug = 0;			# specify debug level using -dN
@@ -191,20 +193,19 @@
 sub create_sh_script
 {
   local ($file) = pop (@_);
+  local ($fh) = pop (@_);
   local ($i) = pop (@_);
 
-  printf (stderr "create_sh_script\n") if ($debug > 0);
+  printf (STDERR "create_sh_script\n") if ($debug > 0);
 
   $! = $fixproc_error;
-  open (file, ">"."$file") || die "$0: cannot open $file\n";
   while ( $shell_lines[$i] ne $shell_end_marker )
     {
-      printf (file "%s", $shell_lines[$i]);
+      printf ($fh "%s", $shell_lines[$i]);
       $i++;
     }
-  close (file);
-  system "chmod +x $file";
-  return file;
+  close ($fh);
+  chmod 0755, $file;
 }
 
 
@@ -212,7 +213,7 @@
 {
   local ($proc) = pop(@_);
 
-  printf (stderr "do_fix\n") if ($debug > 0);
+  printf (STDERR "do_fix\n") if ($debug > 0);
 
   if ($fix{$proc} eq '')
     {
@@ -230,14 +231,13 @@
   else
     {
       # it must be "shell", so execute the shell script defined in database
+      local ($tmpfh, $tmpfile) = tempfile("fix_XXXXXXXX", DIR => "/tmp");
 
-      local ($tmpfile) = "/tmp/fix_$$";
-
-      &create_sh_script ($fix{$proc}, $tmpfile);
+      &create_sh_script ($fix{$proc}, $tmpfh, $tmpfile);
 
       	# return code is number divided by 256
       $error_code = (system "$tmpfile") / 256;
-      system "rm $tmpfile";
+      unlink($tmpfile);
       return ($fix_failed_error) if ($error_code != 0);
         # sleep needed here?
       return &do_exist ($proc);
@@ -249,7 +249,7 @@
 {
   local ($proc) = pop(@_);
 
-  printf (stderr "do_check\n") if ($debug > 0);
+  printf (STDERR "do_check\n") if ($debug > 0);
 
   if ($check{$proc} eq '')
     {
@@ -262,13 +262,13 @@
       # if not "exist", then it must be "shell", so execute the shell script
       # defined in database
 
-      local ($tmpfile) = "/tmp/check_$$";
+      local ($tmpfh, $tmpfile) = tempfile("check_XXXXXXXX", DIR => "/tmp");
 
-      &create_sh_script ($check{$proc}, $tmpfile);
+      &create_sh_script ($fix{$proc}, $tmpfh, $tmpfile);
 
       	# return code is number divided by 256
       $error_code = (system "$tmpfile") / 256;
-      system "rm $tmpfile";
+      unlink($tmpfile);
       return ($check_failed_error) if ($error_code != 0);
 
       # check passed, continue
@@ -281,13 +281,13 @@
 {
   local ($proc) = pop(@_);
 
-  printf (stderr "do_exist\n") if ($debug > 0);
+  printf (STDERR "do_exist\n") if ($debug > 0);
 
   # do ps, check to see if min <= no. of processes <= max
   $! = $fixproc_error;
-  open (command, "/bin/ps -e | /bin/grep $proc | /bin/wc -l |")
+  open (COMMAND, "/bin/ps -e | /bin/grep $proc | /bin/wc -l |")
     || die "$0: can't run ps-grep-wc command\n";
-  $proc_count = <command>;
+  $proc_count = <COMMAND>;
   if (($proc_count < $min{$proc}) || ($proc_count > $max{$proc}))
     {
       return $check_failed_error;
@@ -301,13 +301,13 @@
   local ($proc) = pop(@_);
   local ($second_kill_needed);
 
-  printf (stderr "do_kill\n") if ($debug > 0);
+  printf (STDERR "do_kill\n") if ($debug > 0);
 
   # first try kill
   $! = $fixproc_error;
-  open (command, "/bin/ps -e | /bin/grep $proc |")
+  open (COMMAND, "/bin/ps -e | /bin/grep $proc |")
     || die "$0: can't run ps-grep-awk command\n";
-  while (<command>)
+  while (<COMMAND>)
     {
       # match the first field of ps -e
       $! = $fixproc_error;
@@ -318,10 +318,10 @@
   # if process still exist, try kill -9
   sleep 2;
   $! = $fixproc_error;
-  open (command, "/bin/ps -e | /bin/grep $proc |")
+  open (COMMAND, "/bin/ps -e | /bin/grep $proc |")
     || die "$0: can't run ps-grep-awk command\n";
   $second_kill_needed = 0;
-  while (<command>)
+  while (<COMMAND>)
     {
       # match the first field of ps -e
       $! = $fixproc_error;
@@ -334,9 +334,9 @@
   # see if kill -9 worked
   sleep 2;
   $! = $fixproc_error;
-  open (command, "/bin/ps -e | /bin/grep $proc |")
+  open (COMMAND, "/bin/ps -e | /bin/grep $proc |")
     || die "$0: can't run ps-grep-awk command\n";
-  while (<command>)
+  while (<COMMAND>)
     {				# a process still exist, return error
       return $cannot_kill_error;
     }
@@ -349,7 +349,7 @@
   local ($proc) = pop(@_);
   local ($error_code);
 
-  printf (stderr "do_restart\n") if ($debug > 0);
+  printf (STDERR "do_restart\n") if ($debug > 0);
 
   $error_code = &do_kill ($proc);
   return $error_code if ($error_code != $no_error);
@@ -369,7 +369,7 @@
   local ($proc) = pop(@_);
   local ($error_code);
 
-  printf (stderr "work_on_proc\n") if ($debug > 0);
+  printf (STDERR "work_on_proc\n") if ($debug > 0);
 
   if ($cmd_line_action eq '')
     {
@@ -475,8 +475,8 @@
   local ($str2);
 
   $! = $fixproc_error;
-  open (db, $database_file) || die 'cannot open database file $database_file\n';
-  while (<db>)
+  open (DB, $database_file) || die 'cannot open database file $database_file\n';
+  while (<DB>)
     {
       if ((! /\S/) || (/^[ \t]*#.*$/))
 	{