@@ -459,6 +459,110 @@ void flb_test_unix_path()
459459 flb_socket_close (fd );
460460 test_ctx_destroy (ctx );
461461}
462+
463+
464+ void flb_test_unix_perm ()
465+ {
466+ struct flb_lib_out_cb cb_data ;
467+ struct test_ctx * ctx ;
468+ struct sockaddr_un sun ;
469+ flb_sockfd_t fd ;
470+ int ret ;
471+ int num ;
472+ ssize_t w_size ;
473+ char * unix_path = "in_forward_unix" ;
474+ struct stat sb ;
475+
476+ char * buf ;
477+ size_t size ;
478+
479+ clear_output_num ();
480+
481+ cb_data .cb = cb_check_result_json ;
482+ cb_data .data = "\"test\":\"msg\"" ;
483+
484+ ctx = test_ctx_create (& cb_data );
485+ if (!TEST_CHECK (ctx != NULL )) {
486+ TEST_MSG ("test_ctx_create failed" );
487+ exit (EXIT_FAILURE );
488+ }
489+
490+ ret = flb_input_set (ctx -> flb , ctx -> i_ffd ,
491+ "unix_path" , unix_path ,
492+ "unix_perm" , "0600" ,
493+ NULL );
494+ TEST_CHECK (ret == 0 );
495+
496+ ret = flb_output_set (ctx -> flb , ctx -> o_ffd ,
497+ "match" , "test" ,
498+ "format" , "json" ,
499+ NULL );
500+ TEST_CHECK (ret == 0 );
501+
502+ /* Start the engine */
503+ ret = flb_start (ctx -> flb );
504+ TEST_CHECK (ret == 0 );
505+
506+ /* waiting to create socket */
507+ flb_time_msleep (200 );
508+
509+ memset (& sun , 0 , sizeof (sun ));
510+ fd = socket (AF_LOCAL , SOCK_STREAM , 0 );
511+ if (!TEST_CHECK (fd >= 0 )) {
512+ TEST_MSG ("failed to socket %s, errno=%d" , unix_path , errno );
513+ unlink (unix_path );
514+ exit (EXIT_FAILURE );
515+ }
516+
517+ sun .sun_family = AF_LOCAL ;
518+ strcpy (sun .sun_path , unix_path );
519+ ret = connect (fd , (const struct sockaddr * )& sun , sizeof (sun ));
520+ if (!TEST_CHECK (ret >= 0 )) {
521+ TEST_MSG ("failed to connect, errno=%d" , errno );
522+ flb_socket_close (fd );
523+ unlink (unix_path );
524+ exit (EXIT_FAILURE );
525+ }
526+ create_simple_json (& buf , & size );
527+ w_size = send (fd , buf , size , 0 );
528+ flb_free (buf );
529+ if (!TEST_CHECK (w_size == size )) {
530+ TEST_MSG ("failed to write to %s" , unix_path );
531+ flb_socket_close (fd );
532+ unlink (unix_path );
533+ exit (EXIT_FAILURE );
534+ }
535+
536+ /* waiting to flush */
537+ flb_time_msleep (1500 );
538+
539+ num = get_output_num ();
540+ if (!TEST_CHECK (num > 0 )) {
541+ TEST_MSG ("no outputs" );
542+ }
543+
544+
545+ /* File permission */
546+ ret = stat (unix_path , & sb );
547+ if (!TEST_CHECK (ret == 0 )) {
548+ TEST_MSG ("stat failed. errno=%d" , errno );
549+ test_ctx_destroy (ctx );
550+ exit (EXIT_FAILURE );
551+ }
552+
553+ if (!TEST_CHECK ((sb .st_mode & S_IRWXO ) == 0 )) {
554+ TEST_MSG ("Permssion(others) error. val=0x%x" ,sb .st_mode & S_IRWXO );
555+ }
556+ if (!TEST_CHECK ((sb .st_mode & S_IRWXG ) == 0 )) {
557+ TEST_MSG ("Permssion(group) error. val=0x%x" ,sb .st_mode & S_IRWXG );
558+ }
559+ if (!TEST_CHECK ((sb .st_mode & S_IRWXU ) == (S_IRUSR | S_IWUSR ))) {
560+ TEST_MSG ("Permssion(user) error. val=0x%x" ,sb .st_mode & S_IRWXU );
561+ }
562+
563+ flb_socket_close (fd );
564+ test_ctx_destroy (ctx );
565+ }
462566#endif /* FLB_HAVE_UNIX_SOCKET */
463567
464568
@@ -468,6 +572,7 @@ TEST_LIST = {
468572 {"tag_prefix" , flb_test_tag_prefix },
469573#ifdef FLB_HAVE_UNIX_SOCKET
470574 {"unix_path" , flb_test_unix_path },
575+ {"unix_perm" , flb_test_unix_perm },
471576#endif
472577 {NULL , NULL }
473578};
0 commit comments