Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/utmp.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/utmp.c

    r3232 r3621  
    1717void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname)
    1818{
    19     struct utmp utent;
     19    struct utmpx utent;
    2020    char *id;
    2121    unsigned width;
     
    4646    strncpy(id, tty_name, width);
    4747
    48     touch(_PATH_UTMP);
    49     //utmpname(_PATH_UTMP);
    50     setutent();
     48    touch(_PATH_UTMPX);
     49    //utmpxname(_PATH_UTMPX);
     50    setutxent();
    5151    /* Append new one (hopefully, unless we collide on ut_id) */
    52     pututline(&utent);
    53     endutent();
     52    pututxline(&utent);
     53    endutxent();
    5454
    5555#if ENABLE_FEATURE_WTMP
    5656    /* "man utmp" says wtmp file should *not* be created automagically */
    5757    /*touch(bb_path_wtmp_file);*/
    58     updwtmp(bb_path_wtmp_file, &utent);
     58    updwtmpx(bb_path_wtmp_file, &utent);
    5959#endif
    6060}
     
    6565void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname)
    6666{
    67     struct utmp utent;
    68     struct utmp *utp;
     67    struct utmpx utent;
     68    struct utmpx *utp;
    6969
    70     touch(_PATH_UTMP);
    71     //utmpname(_PATH_UTMP);
    72     setutent();
     70    touch(_PATH_UTMPX);
     71    //utmpxname(_PATH_UTMPX);
     72    setutxent();
    7373
    7474    /* Did init/getty/telnetd/sshd/... create an entry for us?
    7575     * It should be (new_type-1), but we'd also reuse
    7676     * any other potentially stale xxx_PROCESS entry */
    77     while ((utp = getutent()) != NULL) {
     77    while ((utp = getutxent()) != NULL) {
    7878        if (utp->ut_pid == pid
    7979        // && ut->ut_line[0]
     
    8989                memset(utp->ut_host, 0, sizeof(utp->ut_host));
    9090            }
    91             /* NB: pututline (see later) searches for matching utent
    92              * using getutid(utent) - we must not change ut_id
     91            /* NB: pututxline (see later) searches for matching utxent
     92             * using getutxid(utent) - we must not change ut_id
    9393             * if we want *exactly this* record to be overwritten!
    9494             */
     
    9696        }
    9797    }
    98     //endutent(); - no need, pututline can deal with (and actually likes)
     98    //endutxent(); - no need, pututxline can deal with (and actually likes)
    9999    //the situation when utmp file is positioned on found record
    100100
     
    103103            write_new_utmp(pid, new_type, tty_name, username, hostname);
    104104        else
    105             endutent();
     105            endutxent();
    106106        return;
    107107    }
    108108
    109     /* Make a copy. We can't use *utp, pututline's internal getutid
     109    /* Make a copy. We can't use *utp, pututxline's internal getutxid
    110110     * will overwrite it before it is used! */
    111111    utent = *utp;
     
    121121
    122122    /* Update, or append new one */
    123     //setutent();
    124     pututline(&utent);
    125     endutent();
     123    //setutxent();
     124    pututxline(&utent);
     125    endutxent();
    126126
    127127#if ENABLE_FEATURE_WTMP
    128128    /* "man utmp" says wtmp file should *not* be created automagically */
    129129    /*touch(bb_path_wtmp_file);*/
    130     updwtmp(bb_path_wtmp_file, &utent);
     130    updwtmpx(bb_path_wtmp_file, &utent);
    131131#endif
    132132}
     133
     134/* man utmp:
     135 * When init(8) finds that a process has exited, it locates its utmp entry
     136 * by ut_pid, sets ut_type to DEAD_PROCESS, and clears ut_user, ut_host
     137 * and ut_time with null bytes.
     138 * [same applies to other processes which maintain utmp entries, like telnetd]
     139 *
     140 * We do not bother actually clearing fields:
     141 * it might be interesting to know who was logged in and from where
     142 */
     143void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid)
     144{
     145    update_utmp(pid, DEAD_PROCESS, NULL, NULL, NULL);
     146}
Note: See TracChangeset for help on using the changeset viewer.