Changeset 9

Show
Ignore:
Timestamp:
04/20/07 15:42:40 (2 years ago)
Author:
bwilliams
Message:

Removing requirement for libary used only in the examples

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/binary-mq/libsipc/examples/Makefile

    r6 r9  
    1919 
    2020OBJS=mq_creator mq_destroyer mq_sender mq_reader mq_bin_sender mq_bin_reader shm_creator shm_destroyer shm_sender shm_reader  
    21 LDFLAGS=-L../src -lsepol -lsipc -Wl,-rpath,$(SHLIBDIR) 
     21LDFLAGS=-L../src -lsipc -Wl,-rpath,$(SHLIBDIR) 
    2222SUBDIRS=policy 
    2323 
  • branches/binary-mq/libsipc/examples/mq_bin_reader.c

    r6 r9  
    2828#include <sys/types.h> 
    2929#include <sys/ipc.h> 
    30 #include <sepol/policydb.h> 
     30//#include <sepol/policydb.h> 
    3131 
    3232/* Key which sender and receiver have agreed upon */ 
     
    3939#define DATA_END "0xDEADBEEF"   
    4040 
    41 int main(
     41int main(int argc, char **argv
    4242{ 
    4343        int msglen = 0; 
    4444        char *data = NULL; 
    45         sepol_policy_file_t *pf = NULL; 
    46         sepol_policydb_t *policydb = NULL; 
     45        FILE *outfile; 
     46        if (argc<2) { 
     47          printf("usage: %s <output file>\n",argv[0]); 
     48          exit(1); 
     49        } 
     50 
     51        outfile=fopen(argv[1],"wb"); 
     52        if (!outfile) 
     53          { 
     54            printf("Can't open output file %s\n",argv[1]); 
     55            exit(1); 
     56          } 
    4757 
    4858        /* Initialize the IPC handle */ 
     
    5969        } 
    6070         
    61         if (sepol_policy_file_create(&pf)) { 
    62                 fprintf(stderr, "Error creating policy file\n"); 
    63                 return 1; 
    64         } 
    65         if (sepol_policydb_create(&policydb)) { 
    66                 fprintf(stderr, "Error creating policydb\n"); 
    67                 free(pf); 
    68                 return 1; 
    69         } 
    7071 
    71         /* First receive the policydb */ 
     72 
     73        /* First receive the file */ 
    7274        sipc_recv_data(ipc, &data, &msglen); 
    7375        printf("Received %d bytes.\n", msglen); 
    74         sepol_policy_file_set_mem(pf, data, msglen); 
    75         if (sepol_policydb_read(policydb, pf)) { 
    76                 fprintf(stderr, "Error receiving policydb\n"); 
    77                 return 1; 
    78         } 
     76        /* Write it to disk */ 
     77        fwrite(data,1,msglen,outfile); 
     78        fclose(outfile); 
    7979 
    8080        printf("Successfully received policydb\n"); 
     
    8484         
    8585        /* Cleanup */ 
    86         sepol_policydb_free(policydb); 
    87         sepol_policy_file_free(pf); 
    8886        sipc_disconnect(ipc); 
    8987        sipc_destroy_handle(ipc); 
  • branches/binary-mq/libsipc/examples/mq_bin_sender.c

    r6 r9  
    3333#include <fcntl.h> 
    3434#include <errno.h> 
    35 #include <sepol/policydb.h> 
     35 
    3636 
    3737/* Key which sender and receiver have agreed upon */ 
     
    4848#define DATA_END "0xDEADBEEF"   
    4949 
    50 #define POLICY_FILE "/etc/selinux/targeted/policy/policy.21" 
     50//#define POLICY_FILE "/etc/selinux/targeted/policy/policy.21" 
    5151 
    5252/* Send an end of transmission marker */ 
    5353static int send_end_xmit(sipc_t *ipc);   
    5454 
    55 int main(
     55int main(int argc, char **argv
    5656{ 
    5757        int retv = -1; 
     
    5959        int file_data_len = 0; 
    6060        sipc_t *ipc = NULL; 
    61  
     61        if (argc<2) { printf("Usage is %s <input file>\n", argv[0]); 
     62          exit(1); 
     63        } 
     64                          
    6265        /* Initialize and connect IPC handle */ 
    6366        ipc = sipc_init(SIPC_KEY, SIPC_SYSV_MQUEUES, IPC_LEN, 1); 
     
    8083        int fd; 
    8184        struct stat sb; 
    82         fd = open(POLICY_FILE, O_RDONLY); 
     85        fd = open(argv[1], O_RDONLY); 
    8386        if (fd < 0) { 
    84                fprintf(stderr, "Failed to open %s: %s\n", POLICY_FILE
     87          fprintf(stderr, "Failed to open %s: %s\n", argv[1]
    8588                        strerror(errno)); 
    8689                return -1; 
     
    8891        if (fstat(fd, &sb) < 0) { 
    8992                fprintf(stderr, "Failed to fstat %s: %s\n", 
    90                         POLICY_FILE, strerror(errno)); 
     93                        argv[1], strerror(errno)); 
    9194                return -1; 
    9295        } 
     
    9497        file_data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 
    9598        if (file_data == MAP_FAILED) { 
    96                fprintf(stderr, "Failed to mmap %s: %s\n", POLICY_FILE
     99          fprintf(stderr, "Failed to mmap %s: %s\n", argv[1]
    97100                        strerror(errno)); 
    98101                return -1; 
     
    102105        close(fd); 
    103106 
    104         /* Place the policydb into the handle's internal buffer */ 
     107        /* Place the file into the handle's internal buffer */ 
    105108        memcpy(data, file_data, file_data_len); 
    106109 
    107         /* Send the policydb */ 
     110        /* Send the file */ 
    108111        if (sipc_send_data(ipc, file_data_len) < 0) { 
    109112                sipc_error(ipc, "Unable to send message!\n");