~ubuntu-branches/ubuntu/jaunty/pcsc-lite/jaunty-security

« back to all changes in this revision

Viewing changes to src/pcscdaemon.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2007-05-16 14:40:30 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20070516144030-6wk53ou910ctb9ds
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * MUSCLE SmartCard Development ( http://www.linuxnet.com )
3
3
 *
4
 
 * Copyright (C) 1999-2005
 
4
 * Copyright (C) 1999-2002
5
5
 *  David Corcoran <corcoran@linuxnet.com>
 
6
 * Copyright (C) 1999-2007
6
7
 *  Ludovic Rousseau <ludovic.rousseau@free.fr>
7
8
 *
8
 
 * $Id: pcscdaemon.c 2377 2007-02-05 13:13:56Z rousseau $
 
9
 * $Id: pcscdaemon.c 2505 2007-04-12 09:41:13Z rousseau $
9
10
 */
10
11
 
11
12
/**
44
45
#include "readerfactory.h"
45
46
#include "configfile.h"
46
47
#include "powermgt_generic.h"
 
48
#include "utils.h"
47
49
 
48
50
#ifndef TRUE
49
51
#define TRUE 1
68
70
 
69
71
PCSCLITE_MUTEX usbNotifierMutex;
70
72
 
71
 
#ifdef USE_RUN_PID
72
 
pid_t GetDaemonPid(void);
73
 
pid_t GetDaemonPid(void)
74
 
{
75
 
        FILE *f;
76
 
        pid_t pid;
77
 
 
78
 
        /* pids are only 15 bits but 4294967296
79
 
         * (32 bits in case of a new system use it) is on 10 bytes
80
 
         */
81
 
        if ((f = fopen(USE_RUN_PID, "rb")) != NULL)
82
 
        {
83
 
#define PID_ASCII_SIZE 11
84
 
                char pid_ascii[PID_ASCII_SIZE];
85
 
 
86
 
                fgets(pid_ascii, PID_ASCII_SIZE, f);
87
 
                fclose(f);
88
 
 
89
 
                pid = atoi(pid_ascii);
90
 
        }
91
 
        else
92
 
        {
93
 
                Log2(PCSC_LOG_CRITICAL, "Can't open " USE_RUN_PID ": %s",
94
 
                        strerror(errno));
95
 
                return -1;
96
 
        }
97
 
 
98
 
        return pid;
99
 
} /* GetDaemonPid */
100
 
#endif
101
 
 
102
73
int SendHotplugSignal(void)
103
74
{
104
 
#ifdef USE_RUN_PID
105
75
        pid_t pid;
106
76
 
107
77
        pid = GetDaemonPid();
116
86
                        return EXIT_FAILURE ;
117
87
                }
118
88
        }
119
 
#endif
120
89
 
121
90
        return EXIT_SUCCESS;
122
91
} /* SendHotplugSignal */
380
349
 
381
350
        if (rv == 0)
382
351
        {
383
 
#ifdef USE_RUN_PID
384
352
                pid_t pid;
385
353
 
386
354
                /* read the pid file to get the old pid and test if the old pcscd is
406
374
                                clean_temp_files();
407
375
                }
408
376
                else
409
 
#endif
410
377
                {
411
378
                        if (HotPlug)
412
379
                        {
413
 
#ifdef USE_RUN_PID
414
380
                                Log1(PCSC_LOG_CRITICAL, "file " USE_RUN_PID " do not exist");
415
 
#else
416
 
                                Log1(PCSC_LOG_CRITICAL,
417
 
                                        "pcscd was not configured with --enable-runpid=FILE");
418
 
#endif
419
381
                                Log1(PCSC_LOG_CRITICAL, "Hotplug failed");
420
382
                                return EXIT_FAILURE;
421
383
                        }
424
386
                                "file " PCSCLITE_PUBSHM_FILE " already exists.");
425
387
                        Log1(PCSC_LOG_CRITICAL,
426
388
                                "Maybe another pcscd is running?");
427
 
#ifdef USE_RUN_PID
428
389
                        Log1(PCSC_LOG_CRITICAL,
429
390
                                "I can't read process pid from " USE_RUN_PID);
430
 
#endif
431
391
                        Log1(PCSC_LOG_CRITICAL,
432
392
                                "Remove " PCSCLITE_PUBSHM_FILE " and " PCSCLITE_CSOCK_NAME);
433
393
                        Log1(PCSC_LOG_CRITICAL,
460
420
        signal(SIGINT, signal_trap);
461
421
        signal(SIGHUP, signal_trap);
462
422
 
463
 
#ifdef USE_RUN_PID
464
423
        /*
465
424
         * Record our pid to make it easier
466
425
         * to kill the correct pcscd
474
433
                        fclose(f);
475
434
                }
476
435
        }
477
 
#endif
478
436
 
479
437
        /*
480
438
         * If PCSCLITE_IPC_DIR does not exist then create it
585
543
                Log2(PCSC_LOG_ERROR, "Cannot unlink " PCSCLITE_CSOCK_NAME ": %s",
586
544
                        strerror(errno));
587
545
 
588
 
#ifdef USE_RUN_PID
589
546
        rv = SYS_Unlink(USE_RUN_PID);
590
547
        if (rv != 0)
591
548
                Log2(PCSC_LOG_ERROR, "Cannot unlink " USE_RUN_PID ": %s",
592
549
                        strerror(errno));
593
 
#endif
594
550
}
595
551
 
596
552
void signal_reload(int sig)
638
594
{
639
595
        printf("%s version %s.\n",  PACKAGE, VERSION);
640
596
        printf("Copyright (C) 1999-2002 by David Corcoran <corcoran@linuxnet.com>.\n");
641
 
        printf("Copyright (C) 2001-2005 by Ludovic Rousseau <ludovic.rousseau@free.fr>.\n");
 
597
        printf("Copyright (C) 2001-2007 by Ludovic Rousseau <ludovic.rousseau@free.fr>.\n");
642
598
        printf("Copyright (C) 2003-2004 by Damien Sauveron <sauveron@labri.fr>.\n");
643
599
        printf("Report bugs to <sclinux@linuxnet.com>.\n");
644
600
}