DatabaseProcApplicationCreatedLinks
sybsystemprocssp_errorlog  14 déc. 14Defects Propagation Dependencies

1     
2     
3     /*
4     ** SP_ERRORLOG
5     **
6     ** Driver interface to error logging functionality.
7     ** For each feature the underlying driver function/built-in/sub-ordinate stored 
8     ** procedure is called.
9     **
10    ** Syntax
11    **      sp_errorlog ["command" [,"parameter"]]
12    **
13    ** Parameters
14    **	@cmd         - This is the command or action to be performed.
15    **      @subcommand  - This is the parameter supplied for executing the comman
16    **	@param_value - This is the require parameter to be passed for subcommand.
17    **
18    ** Returns
19    **	0       - success
20    **      other   - errors while execution
21    */
22    
23    create or replace procedure sp_errorlog
24    (
25        @cmd varchar(30) = NULL,
26        @subcommand varchar(1024) = NULL,
27        @param_value varchar(30) = NULL
28    )
29    as
30        begin
31            declare @retval int,
32                @msg varchar(256),
33                @flag int,
34                @retstatus int,
35                @nullarg varchar(1),
36                @dummy int,
37                @status int,
38                @gp_enabled int
39    
40    
41    
42            /*
43            **  If we're in a transaction, disallow this since it might make recovery
44            **  impossible.
45            */
46            if @@trancount > 0
47            begin
48                /*  17260, "Can't run %1! from within a transaction."  */
49                raiserror 17260, "sp_errorlog"
50                return (1)
51            end
52            else
53            begin
54                set chained off
55            end
56    
57            set transaction isolation level 1
58            set nocount on
59    
60            /*  Begin command processing. */
61    
62            select @cmd = lower(@cmd)
63            select @param_value = lower(@param_value)
64    
65            If (@cmd is null or @cmd = 'help')
66            begin
67                exec sp_errorlog_showhelp @cmd, @subcommand, @param_value
68                return (0)
69            end
70    
71            if (@cmd = 'change log')
72            begin
73    
74                /* 
75                ** If granular permissions is not enabled then sa_role is required.
76                ** If granular permissions is enabled then the permission manage server 
77                ** is required.
78                */
79                select @nullarg = NULL
80                execute @status = sp_aux_checkroleperm "sa_role",
81                    "manage server", @nullarg, @gp_enabled output
82    
83    
84                /* For Auditing */
85                if (@gp_enabled = 0)
86                begin
87                    if (proc_role("sa_role") = 0)
88                        return 1
89                end
90                else
91                begin
92                    select @dummy = proc_auditperm("manage server", @status)
93                end
94    
95                if (@status != 0)
96                    return 1
97    
98    
99                /* Check if subcommand or param_value entered is valid */
100               if (@subcommand is null or
101                       (@param_value not in ('jslog true', 'jslog false', null)))
102               begin
103                   /* 17932, "You entered an invalid value. No change was made." */
104                   raiserror 17932
105                   return (1)
106               end
107   
108               select @flag = 1
109               if (@param_value = 'jslog false')
110               begin
111                   select @flag = 0
112               end
113   
114               select @retval = errorlog_admin(@cmd, @subcommand)
115               if (@retval = 0)
116               begin
117                   /* 19845, "Change in errorlog path complete. New file: '%1!'" */
118                   exec sp_getmessage 19845, @msg output
119                   print @msg, @subcommand
120                   /* 
121                   ** 19846, "Update the -e argument in the Runserver file with 
122                   **	   the new errorlog path to reflect the errorlog change.
123                   */
124                   exec sp_getmessage 19846, @msg output
125                   print @msg
126               end
127               else if (@retval = 2)
128               begin
129                   /* 19848,"Command already in use by another user or session." */
130                   raiserror 19848
131               end
132               else if (@retval = 4)
133               begin
134                   /* 19847, "File '%1!' did not open for writing." */
135                   raiserror 19847, @subcommand
136               end
137               else if (@retval = 8)
138               begin
139                   /* 19845, "Change in errorlog path complete. New file: '%1!'" */
140                   exec sp_getmessage 19845, @msg output
141                   print @msg, @subcommand
142                   /*
143                   ** 19846, "Update the -e argument in the Runserver file with
144                   **         the new errorlog path to reflect the errorlog change.
145                   */
146                   exec sp_getmessage 19846, @msg output
147                   print @msg
148   
149                   /* 19851, "Warning:Previous errorlog file could not be closed."*/
150                   exec sp_getmessage 19851, @msg output
151                   print @msg
152               end
153               else
154               begin
155                   /* 
156                   ** 19850, "Internal error encountered in opening new errorlog. 
157                   ** 	   Check current ASE errorlog for details." 
158                   */
159                   raiserror 19850
160   
161               end
162   
163               if ((@retval = 0 or @retval = 8) and @flag = 1)
164               begin
165                   /* 
166                   ** Errorlog change was successful. Now change the Job Scheduler 
167                   ** errorlog directory from its current directory to the 
168                   ** directory where new errorlog resides.
169                   */
170   
171                   select @retstatus = js_wakeup('jsagent_log', @flag)
172   
173                   if (@retstatus = 1)
174                   begin
175                       /* 
176                       ** 19852, "Attempting to change the Job Scheduler Agent 
177                       **	   log from its current directory to the directory 
178                       **	   where new ASE errorlog is residing. Check the 
179                       ** 	   JS Agent log and/or ASE errorlog for details." 
180                       */
181                       exec sp_getmessage 19852, @msg output
182                       print @msg
183                   end
184                   else
185                   begin
186                       select @retstatus = js_wakeup('start_js', 0)
187                       if (@retstatus = 1 and @param_value = 'jslog true')
188                       begin
189                           /* 
190                           ** 19853, "The Job Scheduler is not running; 
191                           **	   therefore, no attempt amde to change
192                           **	   location of JS Agent log.
193                           */
194                           raiserror 19853
195                       end
196                       else
197                       begin
198                           if (@retstatus = 0) /* Indicates JS is running */
199                           begin
200                               /* print error when moving to JS agent log */
201                               /*
202                               ** 19856, "Error encountered when moving the
203                               **	   Job Scheduler Agent log from its
204                               ** 	   current directory to the directory
205                               **	   where new errorlog is residing.
206                               **	   Check the previous JS Agent log and/or
207                               **	   ASE errorlog for details."
208                               */
209                               raiserror 19856
210                           end
211                       end
212                   end
213               end
214               return (@retval)
215           end
216           else
217           begin
218   
219               /* 19213, "Invalid argument or unsupported command: %1!." */
220               raiserror 19213, @cmd
221               return (1)
222           end
223       end
224   


exec sp_procxmode 'sp_errorlog', 'AnyMode'
go

Grant Execute on sp_errorlog to public
go
DEFECTS
 MTYP 4 Assignment type mismatch @command: varchar(30) = varchar(1024) 67
 MGTP 3 Grant to public sybsystemprocs..sp_errorlog  
 MNER 3 No Error Check should check return value of exec 67
 MNER 3 No Error Check should check return value of exec 118
 MNER 3 No Error Check should check return value of exec 124
 MNER 3 No Error Check should check return value of exec 140
 MNER 3 No Error Check should check return value of exec 146
 MNER 3 No Error Check should check return value of exec 150
 MNER 3 No Error Check should check return value of exec 181
 MUCO 3 Useless Code Useless Brackets in create proc 24
 MUCO 3 Useless Code Useless Begin-End Pair 30
 MUCO 3 Useless Code Useless Brackets 50
 MUCO 3 Useless Code Useless Brackets 65
 MUCO 3 Useless Code Useless Brackets 68
 MUCO 3 Useless Code Useless Brackets 71
 MUCO 3 Useless Code Useless Brackets 85
 MUCO 3 Useless Code Useless Brackets 87
 MUCO 3 Useless Code Useless Brackets 95
 MUCO 3 Useless Code Useless Brackets 100
 MUCO 3 Useless Code Useless Brackets 105
 MUCO 3 Useless Code Useless Brackets 109
 MUCO 3 Useless Code Useless Brackets 115
 MUCO 3 Useless Code Useless Brackets 127
 MUCO 3 Useless Code Useless Brackets 132
 MUCO 3 Useless Code Useless Brackets 137
 MUCO 3 Useless Code Useless Brackets 163
 MUCO 3 Useless Code Useless Brackets 173
 MUCO 3 Useless Code Useless Brackets 187
 MUCO 3 Useless Code Useless Brackets 198
 MUCO 3 Useless Code Useless Brackets 214
 MUCO 3 Useless Code Useless Brackets 221
 QISO 3 Set isolation level 57
 VNRD 3 Variable is not read @dummy 92
 MTR1 2 Metrics: Comments Ratio Comments: 46% 23
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 16 = 22dec - 8exi + 2 23
 MTR3 2 Metrics: Query Complexity Complexity: 80 23

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)  
calls proc sybsystemprocs..sp_getmessage  
   reads table master..sysmessages (1)  
   reads table sybsystemprocs..sysusermessages  
   reads table master..syslanguages (1)  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
calls proc sybsystemprocs..sp_errorlog_showhelp  
   calls proc sybsystemprocs..sp_getmessage