mozglue/build/cpuacct.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mozglue/build/cpuacct.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/*
     1.5 + * Copyright (C) 2010 The Android Open Source Project
     1.6 + * All rights reserved.
     1.7 + *
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + *  * Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + *  * Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in
    1.15 + *    the documentation and/or other materials provided with the
    1.16 + *    distribution.
    1.17 + *
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    1.21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    1.22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    1.23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    1.24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
    1.25 + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    1.26 + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.27 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.28 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.29 + * SUCH DAMAGE.
    1.30 + */
    1.31 +#include <unistd.h>
    1.32 +#include <errno.h>
    1.33 +#include <sys/stat.h>
    1.34 +#include <fcntl.h>
    1.35 +#include <stdio.h>
    1.36 +#include "cpuacct.h"
    1.37 +
    1.38 +int cpuacct_add(uid_t uid)
    1.39 +{
    1.40 +    int count;
    1.41 +    int fd;
    1.42 +    char buf[80];
    1.43 +
    1.44 +    count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid);
    1.45 +    fd = open(buf, O_RDWR|O_CREAT|O_TRUNC|O_SYNC);
    1.46 +    if (fd < 0) {
    1.47 +        /* Note: sizeof("tasks") returns 6, which includes the NULL char */
    1.48 +        buf[count - sizeof("tasks")] = 0;
    1.49 +        if (mkdir(buf, 0775) < 0)
    1.50 +            return -errno;
    1.51 +
    1.52 +        /* Note: sizeof("tasks") returns 6, which includes the NULL char */
    1.53 +        buf[count - sizeof("tasks")] = '/';
    1.54 +        fd = open(buf, O_RDWR|O_CREAT|O_TRUNC|O_SYNC);
    1.55 +    }
    1.56 +    if (fd < 0)
    1.57 +        return -errno;
    1.58 +
    1.59 +    write(fd, "0", 2);
    1.60 +    if (close(fd))
    1.61 +        return -errno;
    1.62 +
    1.63 +    return 0;
    1.64 +}

mercurial