~ubuntu-branches/ubuntu/trusty/sblim-sfcb/trusty-proposed

« back to all changes in this revision

Viewing changes to cimcClientSfcbLocal.c

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2009-06-08 12:04:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090608120449-byfplk09rqz8rtg6
Tags: 1.3.3-0ubuntu1
* New upstream release.
* debian/rules: Removed rpath hacks, SFCB default build handles that now.
* Removed 1934753-remove-assignment.diff, now upstream.
* Refreshed patch cim-schema-location.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
 
 * $Id: cimcClientSfcbLocal.c,v 1.20 2008/04/16 17:41:29 gdread Exp $
 
3
 * $Id: cimcClientSfcbLocal.c,v 1.27 2009/01/30 23:55:38 buccella Exp $
4
4
 *
5
5
 * © Copyright IBM Corp. 2006, 2007
6
6
 *
29
29
 
30
30
 
31
31
#define CIMCSetStatusWithChars(st,rcp,chars) \
32
 
      { if (st) { (st)->rc=(rcp); \
 
32
      { if (st != NULL) { (st)->rc=(rcp); \
33
33
        (st)->msg=NewCMPIString((chars),NULL); }}
34
34
        
35
35
#define NewCMPIString sfcb_native_new_CMPIString
220
220
}
221
221
 
222
222
extern void setEnumArray(CMPIEnumeration * enumeration,CMPIArray * array);
223
 
 
224
223
static CMPIEnumeration *cpyEnumResponses(BinRequestContext * binCtx,
225
224
                                 BinResponseHdr ** resp,
226
225
                                 int arrLen)
227
226
{
228
227
   int i, c, j;
229
 
   CMPIInstance *inst;
 
228
   union o {
 
229
     CMPIInstance *inst;
 
230
     CMPIObjectPath *path;
 
231
     CMPIConstClass *cls;
 
232
   } object;
230
233
   CMPIArray *ar,*art;
231
234
   CMPIEnumeration *enm;
232
235
   CMPIStatus rc;
233
 
 
 
236
   
234
237
   _SFCB_ENTER(TRACE_CIMXMLPROC, "genEnumResponses");
235
 
 
 
238
   
236
239
   ar = NewCMPIArray(arrLen, binCtx->type, NULL);
237
240
   art = NewCMPIArray(0, binCtx->type, NULL);
238
 
 
 
241
   
239
242
   for (c = 0, i = 0; i < binCtx->rCount; i++) {
240
243
      for (j = 0; j < resp[i]->count; c++, j++) {
241
244
         if (binCtx->type == CMPI_ref)
242
 
            relocateSerializedObjectPath(resp[i]->object[j].data);
 
245
            object.path = relocateSerializedObjectPath(resp[i]->object[j].data);
243
246
         else if (binCtx->type == CMPI_instance)
244
 
            relocateSerializedInstance(resp[i]->object[j].data);
 
247
            object.inst = relocateSerializedInstance(resp[i]->object[j].data);
245
248
         else if (binCtx->type == CMPI_class) {
246
 
            relocateSerializedConstClass(resp[i]->object[j].data);
 
249
            object.cls = relocateSerializedConstClass(resp[i]->object[j].data);
247
250
         }
248
 
    //     inst=CMClone(inst,NULL);
249
 
         rc=CMSetArrayElementAt(ar,c, (CMPIValue*)&inst, binCtx->type);
 
251
    //     object.inst=CMClone(object.inst,NULL);
 
252
         rc=CMSetArrayElementAt(ar,c, (CMPIValue*)&object.inst, binCtx->type);
250
253
      }
251
254
   }
252
255
 
253
256
   enm = NewCMPIEnumeration(art, NULL);
254
257
   setEnumArray(enm,ar);
255
258
   art->ft->release(art);
256
 
 
 
259
   
257
260
   _SFCB_RETURN(enm);
258
261
}
259
262
 
266
269
   switch (ctx->rc) {
267
270
   case MSG_X_NOT_SUPPORTED:
268
271
      m = "Operation not supported yy";
 
272
      r = CMPI_RC_ERR_NOT_SUPPORTED;
269
273
      break;
270
274
   case MSG_X_INVALID_CLASS:
271
275
      m = "Class not found";
1335
1339
      }
1336
1340
      free(sreq);
1337
1341
      if (rc) CIMCSetStatusWithChars(rc, resp->rc, (char*)resp->object[0].data);
 
1342
      free(resp);
1338
1343
      _SFCB_RETURN(NULL);
1339
1344
   }
1340
1345
   else ctxErrResponse(&binCtx,rc);
1514
1519
extern int setupControl(char *fn);
1515
1520
extern int errno;
1516
1521
 
 
1522
static int localConnectCount = 0;
 
1523
static pthread_mutex_t lcc_mutex = PTHREAD_MUTEX_INITIALIZER;
 
1524
 
 
1525
#define CONNECT_LOCK()   pthread_mutex_lock(&lcc_mutex)
 
1526
#define CONNECT_UNLOCK() pthread_mutex_unlock(&lcc_mutex)
 
1527
#define CONNECT_UNLOCK_RETURN(rc) { pthread_mutex_unlock(&lcc_mutex); return (rc);}
 
1528
 
1517
1529
int localConnect(ClientEnv* ce, CMPIStatus *st) 
1518
1530
{
1519
1531
   static struct sockaddr_un serverAddr;
1520
 
   int sock,rc,sfcbSocket;
 
1532
   int sock,rc=0,sfcbSocket;
1521
1533
   void *idData;
1522
1534
   unsigned long int l;
1523
1535
   char *user;
1531
1543
      char id[64];
1532
1544
   } msg;
1533
1545
   
1534
 
   if ((sock=socket(PF_UNIX, SOCK_STREAM, 0))<0) {
1535
 
      return -1;
1536
 
      if (st) {
 
1546
   CONNECT_LOCK();  
 
1547
   if (localConnectCount == 0) {
 
1548
     if ((sock=socket(PF_UNIX, SOCK_STREAM, 0))<0) {
 
1549
       if (st) {
1537
1550
         st->rc=CMPI_RC_ERR_FAILED;
1538
1551
         st->msg=ce->ft->newString(ce,strerror(errno),NULL);
1539
 
      }
1540
 
      return -1;
1541
 
   }
1542
 
   
1543
 
   if (socketName==NULL) {
1544
 
      setupControl(NULL);
1545
 
      rc=getControlChars("localSocketPath", &socketName);    
1546
 
      sunsetControl();
1547
 
      if (rc) {
 
1552
       }
 
1553
       CONNECT_UNLOCK_RETURN(-1);
 
1554
     }
 
1555
     
 
1556
     if (socketName==NULL) {
 
1557
       setupControl(NULL);
 
1558
       rc=getControlChars("localSocketPath", &socketName);    
 
1559
       sunsetControl();
 
1560
       if (rc) {
 
1561
         if (st) {
 
1562
           st->rc=CMPI_RC_ERR_FAILED;
 
1563
           st->msg=ce->ft->newString(ce,"failed to open sfcb local socket",NULL);
 
1564
         }
1548
1565
         fprintf(stderr,"--- Failed to open sfcb local socket (%d)\n",rc);
1549
 
         return -2;
1550
 
      }
1551
 
   }   
 
1566
         close(sock);
 
1567
         CONNECT_UNLOCK_RETURN(-2);
 
1568
       }
 
1569
     }   
 
1570
     
 
1571
     serverAddr.sun_family=AF_UNIX;
 
1572
     strcpy(serverAddr.sun_path,socketName);
 
1573
     
 
1574
     if (connect(sock,(struct sockaddr*)&serverAddr,
 
1575
                 sizeof(serverAddr.sun_family)+strlen(serverAddr.sun_path))<0) {
 
1576
       if (st) {
 
1577
         st->rc=CMPI_RC_ERR_FAILED;
 
1578
         st->msg=ce->ft->newString(ce,strerror(errno),NULL);
 
1579
       }
 
1580
       close(sock);
 
1581
       CONNECT_UNLOCK_RETURN(-1);
 
1582
     }
 
1583
   
 
1584
     msg.size=sizeof(msg)-sizeof(msg.size);
 
1585
     msg.oper=1;
 
1586
     msg.pid=getpid();
 
1587
     user=getenv("USER");
 
1588
     strncpy(msg.id, (user) ? user : "", sizeof(msg.id)-1);
 
1589
     msg.id[sizeof(msg.id)-1]=0;
 
1590
     
 
1591
     l=write(sock, &msg, sizeof(msg)); 
 
1592
     
 
1593
     rc = spRecvCtlResult(&sock, &sfcbSocket,&idData, &l);
 
1594
     if (rc < 0 || sfcbSocket <= 0) {
 
1595
       if (st) {
 
1596
         st->rc=CMPI_RC_ERR_FAILED;
 
1597
         st->msg=ce->ft->newString(ce,"failed to get socket fd for local connect",NULL);
 
1598
       }
 
1599
       fprintf(stderr,"--- Failed to get socket fd for local connect (%d, %d, %lu)\n", rc, sfcbSocket, l);
 
1600
       close(sock);
 
1601
       CONNECT_UNLOCK_RETURN(-3);
 
1602
     }
 
1603
     sfcbSockets.send=sfcbSocket;
1552
1604
 
1553
 
   serverAddr.sun_family=AF_UNIX;
1554
 
   strcpy(serverAddr.sun_path,socketName);
1555
 
   
1556
 
   if (connect(sock,(struct sockaddr*)&serverAddr,
1557
 
      sizeof(serverAddr.sun_family)+strlen(serverAddr.sun_path))<0) {
1558
 
      if (st) {
1559
 
         st->rc=CMPI_RC_ERR_FAILED;
1560
 
         st->msg=ce->ft->newString(ce,strerror(errno),NULL);
1561
 
      }
1562
 
      return -1;
 
1605
     close(sock);
1563
1606
   }
1564
 
   
1565
 
   msg.size=sizeof(msg)-sizeof(msg.size);
1566
 
   msg.oper=1;
1567
 
   msg.pid=getpid();
1568
 
   user=getenv("USER");
1569
 
   strncpy(msg.id, (user) ? user : "", sizeof(msg.id)-1);
1570
 
   msg.id[sizeof(msg.id)-1]=0;
1571
 
   
1572
 
   l=write(sock, &msg, sizeof(msg)); 
1573
 
   
1574
 
   rc = spRecvCtlResult(&sock, &sfcbSocket,&idData, &l);
1575
 
  
1576
 
   sfcbSockets.send=sfcbSocket;
 
1607
   localConnectCount += 1;
 
1608
   CONNECT_UNLOCK();
1577
1609
   localMode=0;
1578
 
   close(sock);
1579
1610
   
1580
 
   return sfcbSocket;
 
1611
   return (rc == 0) ? rc : sfcbSocket;
1581
1612
}
1582
1613
 
1583
1614
static void* release(ClientEnv* ce)
1584
1615
{
1585
1616
   void *lib=ce->hdl;
1586
 
   close(sfcbSockets.send);
 
1617
   CONNECT_LOCK();
 
1618
   if (localConnectCount > 0) localConnectCount -= 1;
 
1619
   if (localConnectCount == 0) {
 
1620
     close(sfcbSockets.send);
 
1621
     sfcbSockets.send = -1;
 
1622
   }
 
1623
   CONNECT_UNLOCK();
1587
1624
   free(ce);
1588
1625
   uninitGarbageCollector();
1589
1626
   return lib;