Tizen 2.1 base
[platform/framework/web/download-provider.git] / src / download-provider-pid.c
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <unistd.h>
18 #include <fcntl.h>
19
20 //////////////////////////////////////////////////////////////////////////
21 /// @brief check whether daemon is alive
22 /// @warning lockfd should be managed without close()
23 /// @param the patch for locking the file
24 int dp_lock_pid(char *path)
25 {
26         int lockfd = -1;
27         if ((lockfd = open(path, O_WRONLY | O_CREAT, (0666 & (~000)))) < 0) {
28                 return -1;
29         } else if (lockf(lockfd, F_TLOCK, 0) < 0) {
30                 close(lockfd);
31                 return -1;
32         }
33         return lockfd;
34 }