316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi Sumit Bose <sbose@redhat.com>
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi Copyright (C) 2017 Red Hat
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi SSSD's enhanced NSS API
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi This program is free software; you can redistribute it and/or modify
3f6149c3fd34f54ab33415bf7141e33fc9822e23Aki Tuomi it under the terms of the GNU General Public License as published by
3f6149c3fd34f54ab33415bf7141e33fc9822e23Aki Tuomi the Free Software Foundation; either version 3 of the License, or
3f6149c3fd34f54ab33415bf7141e33fc9822e23Aki Tuomi (at your option) any later version.
a62dad9ec88bb112079dd95be456d258c6c86369Timo Sirainen This program is distributed in the hope that it will be useful,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi but WITHOUT ANY WARRANTY; without even the implied warranty of
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7ad754fca008f60d348f4296e5831e31ce8cc71Timo Sirainen GNU General Public License for more details.
f86bd28cf4dadc4de794eebf34b28aefc8a3fc3aAki Tuomi You should have received a copy of the GNU General Public License
f86bd28cf4dadc4de794eebf34b28aefc8a3fc3aAki Tuomi along with this program. If not, see <http://www.gnu.org/licenses/>.
a7ad754fca008f60d348f4296e5831e31ce8cc71Timo Sirainen#define NSEC_FROM_MSEC(ms) (((ms) % 1000) * 1000 * 1000)
a7ad754fca008f60d348f4296e5831e31ce8cc71Timo Sirainen/* adopted from timersub() defined in /usr/include/sys/time.h */
a7ad754fca008f60d348f4296e5831e31ce8cc71Timo Sirainen (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi#define TIMESPEC_TO_MS(ts) ( ((ts)->tv_sec * 1000) \
f86bd28cf4dadc4de794eebf34b28aefc8a3fc3aAki Tuomistatic int sss_mt_timedlock(struct sss_mutex *m, struct timespec *endtime)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if (ret != 0) {
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &m->old_cancel_state);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomiint sss_nss_timedlock(unsigned int timeout_ms, int *time_left_ms)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi /* make sure there is no overrun when calculating the time left */
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if (ret != 0) {
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi endtime.tv_sec = starttime.tv_sec + SEC_FROM_MSEC(timeout_ms);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi endtime.tv_nsec = starttime.tv_nsec + NSEC_FROM_MSEC(timeout_ms);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if (ret == 0) {
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if (ret != 0) {