#include "Include/common.h"Vai al codice sorgente di questo file.
Funzioni | |
| static void | byebye () |
| int | main (int argc, char **argv) |
Variabili | |
| message_t | msg |
| channel_t | sk_client |
| char * | path |
This program is free software; you can redistribuite it and/or modify it under the terms of the GNU/General Pubblic License as published the Free software Foundation; either version 2 of the License, or (at your opinion) any later version.
Definizione nel file sfat_mkdir.c.
| void byebye | ( | ) | [static] |
exit function
Definizione alla linea 93 del file sfat_mkdir.c.
00093 { 00094 extern message_t msg; 00095 extern char * path; 00096 extern channel_t sk_client; 00097 00098 /* Chiudo la socket di comunicazione del client */ 00099 if (sk_client != -1) closeConnection(sk_client); 00100 00101 if (msg.buffer!=NULL) free(msg.buffer); 00102 if (path!=NULL) free(path); 00103 }
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Comando: sfat_mkdir dir1/.../dirk/dir
crea una directory "dir" nella directory "dir1/.../dirk/", se non esiste alcun file o directory con lo stesso nome. Tutte le directory "dir1/.../dirk/" devono esistere.
All'invocazione il client controlla i parametri e contatta il server inviando una richiesta di connessione sul socket.
Se la connessione ha successo il client invia una richiesta di MSG_MKDIR.
Tutti gli errori sono riportati sullo standar error.
Definizione alla linea 33 del file sfat_mkdir.c.
00033 { 00034 extern message_t msg; 00035 extern channel_t sk_client; 00036 extern char * path; 00037 00038 sk_client = 0; 00039 path = NULL; 00040 msg.buffer = NULL; 00041 00042 if ((atexit(byebye))!=0){ 00043 errore(__FILE__,__LINE__,"sfat_mkdir: cannot set exit function",errno); 00044 exit(EXIT_FAILURE); 00045 } 00046 00047 /* Argomenti da riga di comando */ 00048 if (argc<2){ 00049 fprintf(stderr, 00050 "sfat_mkdir: errore non e' stato passato alcun nome per la cartella da creare\n"); 00051 exit(EXIT_FAILURE); 00052 } 00053 00054 if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){ 00055 errore(__FILE__,__LINE__, 00056 "sfat_mkdir: error on allocate memory for 'path'",errno); 00057 exit(EXIT_FAILURE); 00058 } 00059 strncpy(path,TMP,strlen(TMP)); 00060 strncat(path,SKTNAME,strlen(SKTNAME)); 00061 00062 msg.type = MSG_MKDIR; 00063 msg.length = strlen(argv[1])+1; 00064 if (!(msg.buffer = malloc(msg.length))){ 00065 errore(__FILE__,__LINE__, 00066 "sfat_mkdir: error on allocate memory for 'buffer'",errno); 00067 exit(EXIT_FAILURE); 00068 } 00069 memset(msg.buffer, 0x0, msg.length); 00070 /* uso strncat perche' termina la stringa */ 00071 strncat(msg.buffer,argv[1],msg.length); 00072 00073 /* Apro la socket di comunicazione col server */ 00074 if ((sk_client = openConnection(path)) == -1) { 00075 fprintf(stderr,"sfat_read: Errore nella apertura del socket di comunicazione\n"); 00076 exit(EXIT_FAILURE); 00077 } 00078 else if (sk_client == SFATENAMETOOLONG){ 00079 fprintf(stderr,"sfat_read: Error Path Too Long (exceeding UNIX_PATH_MAX)\n"); 00080 exit(EXIT_FAILURE); 00081 } 00082 00083 if (sendMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE); 00084 if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE); 00085 if (msg.type==MSG_OK) 00086 printf("sfat_mkdir: %s created!\n", argv[1]); 00087 else exit(EXIT_FAILURE); 00088 00089 exit(EXIT_SUCCESS); 00090 return 0; 00091 }
struttura rappresentante un messaggio tra client e server
Definizione alla linea 18 del file sfat_mkdir.c.
tipo descrittore del canale di comunicazione (server e client)
Definizione alla linea 19 del file sfat_mkdir.c.
| char* path |
directory e nome del socket AF_UNIX
Definizione alla linea 20 del file sfat_mkdir.c.
1.6.3