Commits

Anonymous committed a9168e7

6811703 System crashing while running snv_109 on WhiteBox QuadXeon

Comments (0)

Files changed (2)

usr/src/cmd/smbsrv/smbd/smbd.h

 	int		s_door_srv;
 	int		s_door_opipe;
 	int		s_secmode;	/* Current security mode */
+	boolean_t	s_nbt_listener_running;
+	boolean_t	s_tcp_listener_running;
+	pthread_t	s_nbt_listener_id;
+	pthread_t	s_tcp_listener_id;
 } smbd_t;
 
 #ifdef __cplusplus

usr/src/cmd/smbsrv/smbd/smbd_main.c

 static void *smbd_refresh_monitor(void *);
 static void smbd_refresh_dc(void);
 
-static pthread_t nbt_listener;
-static pthread_t tcp_listener;
+static int smbd_start_listeners(void);
+static void smbd_stop_listeners(void);
+
 static pthread_t refresh_thr;
 static pthread_cond_t refresh_cond;
 static pthread_mutex_t refresh_mutex;
 static int
 smbd_kernel_bind(void)
 {
-	pthread_attr_t	tattr;
 	smb_io_t	smb_io;
-	int		rc1;
-	int		rc2;
 	int		rc;
 
 	bzero(&smb_io, sizeof (smb_io));
 		return (errno);
 	}
 
-	(void) pthread_attr_init(&tattr);
-	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
-
-	rc1 = pthread_create(&nbt_listener, &tattr, smbd_nbt_listener, NULL);
-	if (rc1 != 0)
-		smbd_report("unable to start NBT service");
-
-	rc2 = pthread_create(&tcp_listener, &tattr, smbd_tcp_listener, NULL);
-	if (rc2 != 0)
-		smbd_report("unable to start TCP service");
-
-	(void) pthread_attr_destroy(&tattr);
-
-	rc = rc1;
-	if (rc == 0)
-		rc = rc2;
-
+	rc = smbd_start_listeners();
 	if (rc == 0) {
 		smbd.s_kbound = B_TRUE;
 		return (0);
 	}
-
+	smbd_stop_listeners();
 	(void) close(smbd.s_drv_fd);
 	smbd.s_drv_fd = -1;
 	return (rc);
 smbd_kernel_unbind(void)
 {
 	if (smbd.s_drv_fd != -1) {
+		smbd_stop_listeners();
 		(void) close(smbd.s_drv_fd);
 		smbd.s_drv_fd = -1;
 		smbd.s_kbound = B_FALSE;
 	(void) fprintf(stderr, "smbd: %s\n", buf);
 }
 
+static int
+smbd_start_listeners(void)
+{
+	int		rc1;
+	int		rc2;
+	pthread_attr_t	tattr;
+
+	(void) pthread_attr_init(&tattr);
+
+	if (!smbd.s_nbt_listener_running) {
+		rc1 = pthread_create(&smbd.s_nbt_listener_id, &tattr,
+		    smbd_nbt_listener, NULL);
+		if (rc1 != 0)
+			smbd_report("unable to start NBT service");
+		else
+			smbd.s_nbt_listener_running = B_TRUE;
+	}
+
+	if (!smbd.s_tcp_listener_running) {
+		rc2 = pthread_create(&smbd.s_tcp_listener_id, &tattr,
+		    smbd_tcp_listener, NULL);
+		if (rc2 != 0)
+			smbd_report("unable to start TCP service");
+		else
+			smbd.s_tcp_listener_running = B_TRUE;
+	}
+
+	(void) pthread_attr_destroy(&tattr);
+
+	if (rc1 != 0)
+		return (rc1);
+	return (rc2);
+}
+
+static void
+smbd_stop_listeners(void)
+{
+	void	*status;
+
+	if (smbd.s_nbt_listener_running) {
+		(void) pthread_kill(smbd.s_nbt_listener_id, SIGTERM);
+		(void) pthread_join(smbd.s_nbt_listener_id, &status);
+		smbd.s_nbt_listener_running = B_FALSE;
+	}
+
+	if (smbd.s_tcp_listener_running) {
+		(void) pthread_kill(smbd.s_tcp_listener_id, SIGTERM);
+		(void) pthread_join(smbd.s_tcp_listener_id, &status);
+		smbd.s_tcp_listener_running = B_FALSE;
+	}
+}
+
 /*
  * Enable libumem debugging by default on DEBUG builds.
  */