Exemple #1
0
int cmd_quit(const char* UNUSED(arg)) {
	done = 1;
	ncds_cleanall();
	remove_all_hints();
	return 0;
}
Exemple #2
0
API int nc_close(void)
{
	int retval = 0, i, fd;
	char my_comm[NC_APPS_COMM_MAX+1];

#ifndef DISABLE_LIBSSH
	if (nc_init_flags & NC_INIT_LIBSSH_PTHREAD) {
		ssh_finalize();
	}
#endif

	if (nc_init_flags & NC_INIT_CLIENT) {
		return (retval);
	}

	/* get my comm */
	my_comm[0] = '\0';
	fd = open("/proc/self/comm", O_RDONLY);
	if (fd != -1) {
		i = read(fd, my_comm, NC_APPS_COMM_MAX);
		close(fd);
		if (i > 0) {
			if (my_comm[i-1] == '\n') {
				my_comm[i-1] = '\0';
			} else {
				my_comm[i] = '\0';
			}
		}
	}

	nc_init_flags |= NC_INIT_CLOSING;

	/* nc_apps_check() also deletes this process's info from the shared memory */
	if (nc_info != NULL) {
		/* LOCK */
		pthread_rwlock_wrlock(&(nc_info->lock));
		if (nc_apps_check(my_comm, &(nc_info->apps)) == 1 && nc_init_flags & NC_INIT_MULTILAYER) {
			/* UNLOCK */
			pthread_rwlock_unlock(&(nc_info->lock));
			/* delete the shared memory */
			retval = nc_shared_cleanup(1);
		} else {
			nc_info->stats.participants--;
			/* UNLOCK */
			pthread_rwlock_unlock(&(nc_info->lock));
		}

#ifdef POSIX_SHM
		munmap(nc_info, sizeof(struct nc_shared_info));
#else
		shmdt(nc_info);
#endif /* #ifdef POSIX_SHM */
		nc_info = NULL;
	}

	if (retval == -1) {
		nc_init_flags &= ~NC_INIT_CLOSING;
		return (retval);
	}

	/* close NETCONF session statistics */
	if (nc_init_flags & NC_INIT_MONITORING) {
		nc_session_monitoring_close();
	}

	/* close all remaining datastores */
	if (nc_init_flags & NC_INIT_DATASTORES) {
		ncds_cleanall();
	}

#ifndef DISABLE_NOTIFICATIONS
	/* close Notification subsystem */
	if (nc_init_flags & NC_INIT_NOTIF) {
		ncntf_close();
	}
#endif
	/* close Access Control subsystem */
	if (nc_init_flags & NC_INIT_NACM) {
		nacm_close();
	}

	xsltCleanupGlobals();
	xmlCleanupParser();

	nc_init_flags = 0;
	return (retval);
}