~ubuntu-branches/ubuntu/precise/net-snmp/precise

« back to all changes in this revision

Viewing changes to snmplib/snmp_logging.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-28 14:59:36 UTC
  • mfrom: (1.2.3 upstream) (1.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20100628145936-cbiallic69pn044g
Tags: 5.4.3~dfsg-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Set Ubuntu maintainer address.
  - net-snmp-config: Use bash. (LP: #104738)
  - Removed multiuser option when calling update-rc.d. (LP: #254261)
  - debian/snmpd.init: LSBify the init script.
  - debian/patches/52_fix_snmpcmd_1_typo.patch: Adjust a typo in snmpcmd.1
    (LP: #250459)
  - debian/snmpd.postinst: source debconf before doing work, LP: #589056
  - debian/snmp.preinst, debian/snmp.prerm: kill any/all processes owned by
    snmp user before install/uninstall, LP: #573391
  - Add apport hook (LP: #533603):
  - debian/{snmp,snmpd}.apport: Added.
  - debian/control: Build-depends on dh-apport.
  - debian/rules: 
    + Add --with apport.
    + override_dh_apport to install hook on snmpd package only.
 * Dropped patches:
   - debian/patches/99-fix-ubuntu-div0.patch: Fix dvision by zero.. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
#define LOG_USER        0
175
175
#endif
176
176
 
 
177
/*
 
178
 * Decodes log priority.
 
179
 * @param optarg - IN - priority to decode, "0" or "0-7"
 
180
 *                 OUT - points to last character after the decoded priority
 
181
 * @param pri_max - OUT - maximum priority (i.e. 0x7 from "0-7")
 
182
 */
177
183
int
178
 
decode_priority( char *optarg, int *pri_max )
 
184
decode_priority( char **optarg, int *pri_max )
179
185
{
180
186
    int pri_low = LOG_DEBUG;
181
187
 
182
 
    if (optarg == NULL)
 
188
    if (*optarg == NULL)
183
189
        return -1;
184
190
 
185
 
    switch (*optarg) {
 
191
    switch (**optarg) {
186
192
        case '0': 
187
193
        case '!': 
188
194
            pri_low = LOG_EMERG;
223
229
            pri_low = LOG_DEBUG;
224
230
            break;
225
231
        default: 
226
 
            fprintf(stderr, "invalid priority: %c\n",*optarg);
 
232
            fprintf(stderr, "invalid priority: %c\n",**optarg);
227
233
            return -1;
228
234
    }
 
235
    *optarg = *optarg+1;
229
236
 
230
 
    if (pri_max && *(optarg+1)=='-') {
231
 
        *pri_max = decode_priority( optarg+2, NULL );
 
237
    if (pri_max && **optarg=='-') {
 
238
        *optarg = *optarg + 1; /* skip '-' */
 
239
        *pri_max = decode_priority( optarg, NULL );
232
240
        if (*pri_max == -1) return -1;
 
241
        if (pri_low < *pri_max) { 
 
242
            int tmp = pri_low; 
 
243
            pri_low = *pri_max; 
 
244
            *pri_max = tmp; 
 
245
        }
 
246
 
233
247
    }
234
248
    return pri_low;
235
249
}
325
339
     * Log to Standard Error
326
340
     */
327
341
    case 'E':
328
 
        priority = decode_priority( optarg, &pri_max );
 
342
        priority = decode_priority( &optarg, &pri_max );
329
343
        if (priority == -1)  return -1;
330
344
        if (inc_optind)
331
345
            optind++;
342
356
     * Log to Standard Output
343
357
     */
344
358
    case 'O':
345
 
        priority = decode_priority( optarg, &pri_max );
 
359
        priority = decode_priority( &optarg, &pri_max );
346
360
        if (priority == -1)  return -1;
347
361
        if (inc_optind)
348
362
            optind++;
360
374
     * Log to a named file
361
375
     */
362
376
    case 'F':
363
 
        priority = decode_priority( optarg, &pri_max );
 
377
        priority = decode_priority( &optarg, &pri_max );
364
378
        if (priority == -1 || !argv)  return -1;
365
379
        optarg = argv[++optind];
366
380
        /* Fallthrough */
385
399
     * Log to syslog
386
400
     */
387
401
    case 'S':
388
 
        priority = decode_priority( optarg, &pri_max );
 
402
        priority = decode_priority( &optarg, &pri_max );
389
403
        if (priority == -1 || !argv)  return -1;
390
 
        optarg++;
 
404
        if (!optarg[0]) {
 
405
            /* The command line argument with priority does not contain log
 
406
             * facility. The facility must be in next argument then. */
 
407
            optind++;
 
408
            if (optind < argc)
 
409
                optarg = argv[optind];
 
410
        }
391
411
        /* Fallthrough */
392
412
    case 's':
393
413
        if (inc_optind)
411
431
     * Don't log 
412
432
     */
413
433
    case 'N':
414
 
        priority = decode_priority( optarg, &pri_max );
 
434
        priority = decode_priority( &optarg, &pri_max );
415
435
        if (priority == -1)  return -1;
416
436
        if (inc_optind)
417
437
            optind++;
777
797
    netsnmp_log_handler *logh;
778
798
    int                  found = 0;
779
799
 
780
 
    for (logh = logh_head; logh; logh = logh->next) {
781
 
        if (logh->type == NETSNMP_LOGHANDLER_CALLBACK)
 
800
    for (logh = logh_head; logh; logh = logh->next)
 
801
        if (logh->type == NETSNMP_LOGHANDLER_CALLBACK) {
782
802
            logh->enabled = 1;
783
803
            found         = 1;
784
804
        }