<commit_before>/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2006 University of Utah and the Flux Group.
 *
 * netmond, a 'server' for libnetmon - simply repeat what a process being
 * monitored with libnetmon tell us on a unix-domian socket
 *
 * TODO: Handle more than one client at a time
 */

#define SOCKPATH "/var/tmp/netmon.sock"

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>
#include <sys/select.h>

int main() {

    int sockfd;
    struct sockaddr_un servaddr;
    int max_clientfd;
    fd_set real_fdset, returned_fdset;
    int i;

    /*
     * Make ourselves a socket
     */
    sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);

    /*
     * Bind to a local socket
     */
    unlink(SOCKPATH);
    servaddr.sun_family = AF_LOCAL;
    strcpy(servaddr.sun_path, SOCKPATH);
    
    if (bind(sockfd, (struct sockaddr*) &servaddr, sizeof(servaddr))) {
        perror("Failed to bind() socket\n");
        return 1;
    }

    if (listen(sockfd, 10)) {
        perror("Failed to listen() on socket\n");
        return 1;
    }

    FD_ZERO(&real_fdset);
    FD_SET(sockfd,&real_fdset);
    max_clientfd = sockfd;

    while (1) {
        /*
         * Make a blocking call to select() to wait for a client to connect or 
         * send us data
         */
        /* fprintf(stderr,"Waiting for clients\n"); */
        bcopy(&real_fdset,&returned_fdset,sizeof(fd_set));

        if (select(max_clientfd + 1,&returned_fdset,NULL,NULL,NULL) <= 0) {
            /* 
             * Just repeat in case of failure
             */
            continue;
        }

        /*
         * Let's see if we got any new clients on our listen socket
         */
        if (FD_ISSET(sockfd,&returned_fdset)) {
            struct sockaddr_un clientaddr;
            socklen_t clientlen;
            int clientfd;
            clientlen = sizeof(clientaddr);
            clientfd = accept(sockfd, (struct sockaddr*)&clientaddr, &clientlen);

            if (clientfd) {<commit_msg>chmod() the socket to 0666 after opening it, so that if netmod is running as root, processes running as a regular user can connect to it.<commit_after>/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2006 University of Utah and the Flux Group.
 *
 * netmond, a 'server' for libnetmon - simply repeat what a process being
 * monitored with libnetmon tell us on a unix-domian socket
 */

#define SOCKPATH "/var/tmp/netmon.sock"

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>
#include <sys/select.h>
#include <sys/stat.h>

int main() {

    int sockfd;
    struct sockaddr_un servaddr;
    int max_clientfd;
    fd_set real_fdset, returned_fdset;
    int i;

    /*
     * Make ourselves a socket
     */
    sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);

    /*
     * Bind to a local socket
     */
    unlink(SOCKPATH);
    servaddr.sun_family = AF_LOCAL;
    strcpy(servaddr.sun_path, SOCKPATH);
    
    if (bind(sockfd, (struct sockaddr*) &servaddr, sizeof(servaddr))) {
        perror("Failed to bind() socket\n");
        return 1;
    }

    if (listen(sockfd, 10)) {
        perror("Failed to listen() on socket\n");
        return 1;
    }

    if (chmod(SOCKPATH,0666)) {
        perror("Failed to chmod() socket\n");
        return 1;
    }

    /*
     * We have to do this because netmod may be run as root, but we want to
     * make sure any user can use it.
     */

    FD_ZERO(&real_fdset);
    FD_SET(sockfd,&real_fdset);
    max_clientfd = sockfd;

    while (1) {
        /*
         * Make a blocking call to select() to wait for a client to connect or 
         * send us data
         */
        /* fprintf(stderr,"Waiting for clients\n"); */
        bcopy(&real_fdset,&returned_fdset,sizeof(fd_set));

        if (select(max_clientfd + 1,&returned_fdset,NULL,NULL,NULL) <= 0) {
            /* 
             * Just repeat in case of failure
             */
            continue;
        }

        /*
         * Let's see if we got any new clients on our listen socket
         */
        if (FD_ISSET(sockfd,&returned_fdset)) {
            struct sockaddr_un clientaddr;
            socklen_t clientlen;
            int clientfd;
            clientlen = sizeof(clientaddr);
            clientfd = accept(sockfd, (struct sockaddr*)&clientaddr, &clientlen);

            if (clientfd) {
{'fraction_non_alphanumeric': 0.11281935338005879, 'fraction_numerical': 0.007460999321727334, 'mean_word_length': 2.2011577424023154, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1328157', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1409, 'n_words': 409}