示例#1
0
文件: server_ipc.c 项目: hajuuk/R7000
/*!
 * Connect to UNIX domain socket "name" for IPC with new afpd master
 *
 * 1. Connect
 * 2. send pid, which establishes a child structure for us in the master
 *
 * @args name    (r) file name to use for UNIX domain socket
 * @returns      socket fd, -1 on error
 */
int ipc_client_uds(const char *name)
{
    EC_INIT;
    struct sockaddr_un address;
    socklen_t address_length;
    int fd = -1;
    pid_t pid = getpid();

    EC_NEG1_LOG( fd = socket(PF_UNIX, SOCK_STREAM, 0) );
    EC_ZERO_LOG( setnonblock(fd, 1) );
    address.sun_family = AF_UNIX;
    address_length = sizeof(address.sun_family) + sprintf(address.sun_path, name);

    EC_ZERO_LOG( connect(fd, (struct sockaddr *)&address, address_length) ); /* 1 */
    LOG(log_debug, logtype_afpd, "ipc_client_uds: connected to master");

    if (writet(fd, &pid, sizeof(pid_t), 0, 1) != sizeof(pid_t)) {
        LOG(log_error, logtype_afpd, "ipc_client_uds: writet: %s", strerror(errno));
        EC_FAIL;
    }

EC_CLEANUP:
    if (ret != 0) {
        return -1;
    }
    LOG(log_debug, logtype_afpd, "ipc_client_uds: fd: %d", fd);
    return fd;
}
示例#2
0
static int ad_conv_v22ea_rf(const char *path, const struct stat *sp, const struct vol *vol)
{
    EC_INIT;
    struct adouble adv2;
    struct adouble adea;

    LOG(log_debug, logtype_default,"ad_conv_v22ea_rf(\"%s\"): BEGIN", fullpathname(path));

    if (S_ISDIR(sp->st_mode))
        return 0;

    ad_init(&adea, vol);
    ad_init_old(&adv2, AD_VERSION2, adea.ad_options);

    /* Open and lock adouble:v2 file */
    EC_ZERO( ad_open(&adv2, path, ADFLAGS_HF | ADFLAGS_RF | ADFLAGS_RDWR) );

    if (adv2.ad_rlen > 0) {
        EC_NEG1_LOG( ad_tmplock(&adv2, ADEID_RFORK, ADLOCK_WR | ADLOCK_FILELOCK, 0, 0, 0) );

        /* Create a adouble:ea resource fork */
        EC_ZERO_LOG( ad_open(&adea, path, ADFLAGS_HF | ADFLAGS_RF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) );

        EC_ZERO_LOG( copy_fork(ADEID_RFORK, &adea, &adv2) );
        adea.ad_rlen = adv2.ad_rlen;
        ad_flush(&adea);
    }

EC_CLEANUP:
    EC_ZERO_LOG( ad_close(&adv2, ADFLAGS_HF | ADFLAGS_RF) );
    EC_ZERO_LOG( ad_close(&adea, ADFLAGS_HF | ADFLAGS_RF) );
    LOG(log_debug, logtype_default,"ad_conv_v22ea_rf(\"%s\"): END: %d", fullpathname(path), ret);
    EC_EXIT;
}
示例#3
0
文件: server_ipc.c 项目: hajuuk/R7000
/*!
 * Listen on UNIX domain socket "name" for IPC from old sesssion
 *
 * @args name    (r) file name to use for UNIX domain socket
 * @returns      socket fd, -1 on error
 */
int ipc_server_uds(const char *name)
{
    EC_INIT;
    struct sockaddr_un address;
    socklen_t address_length;
    int fd = -1;

    EC_NEG1_LOG( fd = socket(PF_UNIX, SOCK_STREAM, 0) );
    EC_ZERO_LOG( setnonblock(fd, 1) );
    unlink(name);
    address.sun_family = AF_UNIX;
    address_length = sizeof(address.sun_family) + sprintf(address.sun_path, name);
    EC_ZERO_LOG( bind(fd, (struct sockaddr *)&address, address_length) );
    EC_ZERO_LOG( listen(fd, 1024) );

EC_CLEANUP:
    if (ret != 0) {
        return -1;
    }

    return fd;
}
示例#4
0
static int ad_conv_v22ea_hf(const char *path, const struct stat *sp, const struct vol *vol)
{
    EC_INIT;
    struct adouble adv2;
    struct adouble adea;
    const char *adpath;
    int adflags;
    uint32_t ctime, mtime, afpinfo = 0;
    char *emptyad;

    LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): BEGIN", fullpathname(path));

    ad_init(&adea, vol);
    ad_init_old(&adv2, AD_VERSION2, adea.ad_options);
    adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0;

    /* Open and lock adouble:v2 file */
    EC_ZERO( ad_open(&adv2, path, adflags | ADFLAGS_HF | ADFLAGS_RDWR) );

    EC_NEG1_LOG( ad_tmplock(&adv2, ADEID_RFORK, ADLOCK_WR | ADLOCK_FILELOCK, 0, 0, 0) );
    EC_NEG1_LOG( adv2.ad_ops->ad_header_read(path, &adv2, sp) );

    /* Check if it's a non-empty header */
    if (S_ISREG(sp->st_mode))
        emptyad = &emptyfilad[0];
    else
        emptyad = &emptydirad[0];

    if (ad_getentrylen(&adv2, ADEID_COMMENT) != 0)
        goto copy;
    if (ad_getentryoff(&adv2, ADEID_FINDERI)
        && (ad_getentrylen(&adv2, ADEID_FINDERI) == ADEDLEN_FINDERI)
        && (memcmp(ad_entry(&adv2, ADEID_FINDERI), emptyad, ADEDLEN_FINDERI) != 0))
        goto copy;
    if (ad_getentryoff(&adv2, ADEID_FILEDATESI)) {
        EC_ZERO_LOG( ad_getdate(&adv2, AD_DATE_CREATE | AD_DATE_UNIX, &ctime) );
        EC_ZERO_LOG( ad_getdate(&adv2, AD_DATE_MODIFY | AD_DATE_UNIX, &mtime) );
        if ((ctime != mtime) || (mtime != sp->st_mtime))
            goto copy;
    }
    if (ad_getentryoff(&adv2, ADEID_AFPFILEI)) {
        if (memcmp(ad_entry(&adv2, ADEID_AFPFILEI), &afpinfo, ADEDLEN_AFPFILEI) != 0)
            goto copy;
    }

    LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): default adouble", fullpathname(path), ret);
    goto EC_CLEANUP;

copy:
    /* Create a adouble:ea meta EA */
    LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): copying adouble", fullpathname(path), ret);
    EC_ZERO_LOGSTR( ad_open(&adea, path, adflags | ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE),
                    "ad_conv_v22ea_hf(\"%s\"): error creating metadata EA: %s",
                    fullpathname(path), strerror(errno));
    EC_ZERO_LOG( ad_copy_header(&adea, &adv2) );
    ad_flush(&adea);

EC_CLEANUP:
    EC_ZERO_LOG( ad_close(&adv2, ADFLAGS_HF | ADFLAGS_SETSHRMD) );
    EC_ZERO_LOG( ad_close(&adea, ADFLAGS_HF | ADFLAGS_SETSHRMD) );
    LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): END: %d", fullpathname(path), ret);
    EC_EXIT;
}